Page 1 of 1
Mod Rewrite Rule appending to css js and images paths
Posted: Tue Jan 20, 2009 12:10 am
by frank_mark
Hi all, I am having some problems with my implementation of rewrite rule.
I have the following code in my .htaccess:
Code: Select all
RewriteEngine On
RewriteBase /
RewriteRule ^food/([0-9]+)$ index.php?view=show_category&id=$1 [L]
RewriteRule ^vision$ index.php?view=vision [L]
following is my css and it is not in the document root (as is the product image folder and various includes):
Code: Select all
<link href='css/style.css' rel='stylesheet' type='text/css' />
Rewriting itself works perfectly fine, however, if I use the rewrite rule in line 5 the css is loaded perfectly, but if I use the rewrite rule in line 4 all my links to images, css, javascripts have an appended 'food/' to their path.
I have tried adding the front slash to the beginning of my css, however that seems to not make the css work on any rewrite rules. If I do add the entire absolute path to my css as such:
Code: Select all
<link href=http:/localhost/css/style.css' rel='stylesheet' type='text/css' />
it works fine. This is not a practical solution I'm guessing.
Anyone have any suggestions?? I would immensely appreciate it. Thanks!!
Re: Mod Rewrite Rule appending to css js and images paths
Posted: Tue Jan 20, 2009 12:46 am
by requinix
Using /css/style.css (with the slash) should work perfectly fine. You say you tried that?
Code: Select all
<link href='/css/style.css' rel='stylesheet' type='text/css' />
Re: Mod Rewrite Rule appending to css js and images paths
Posted: Tue Jan 20, 2009 3:21 am
by wpsd2006
another stupid method but definitly work 100%
you write a full address for image css or even the script
<link href='
http://www.mysite.com/css/style.css' rel='stylesheet' type='text/css' />
for image also src="
http://www.mysite.com/css/image.jpg"
you can DEFINE the website address and apply it on the rest of image
so when you change your web name you only need to change in the DEFINE
oh and dont use the $_SERVER['DOCUMENT_ROOT'] its better using the web address
Re: Mod Rewrite Rule appending to css js and images paths
Posted: Tue Jan 20, 2009 3:52 am
by requinix
wpsd2006 wrote:another stupid method but definitly work 100%
you write a full address for image css or even the script
I seem to recall him saying something about "it works fine" but it's "not a practical solution".
(I agree.)
Re: Mod Rewrite Rule appending to css js and images paths
Posted: Tue Jan 20, 2009 5:26 pm
by pickle
What is an example of a fully qualified URL that you want rewritten (ie:
http://www.example.com/food/99 ) ?
What is the fully qualified URL of your CSS (ie:
http://www.example.com/css/style.css) ?
Re: Mod Rewrite Rule appending to css js and images paths
Posted: Thu Jan 22, 2009 7:13 pm
by wpsd2006
I seem to recall him saying something about "it works fine" but it's "not a practical solution".
(I agree.)
well it works both in my server and localhost ( sometime when i user e.g '/style.css' the '/' wont work in my localhost )
and fits nicely in every browser
no security vulnerability in this right i mean showing your
http://website.com/bla bla bla
than showing the directory root of your server
Re: Mod Rewrite Rule appending to css js and images paths
Posted: Thu Jan 22, 2009 9:37 pm
by frank_mark
Thanks for you help guys. Immensely appreciated. This forum by stretches of the universe has a better (in number and quality) response rate.
Much appreciated. It seems that when I uploaded to the live server for testing it somehow worked.
I am terrified because I have no clue what the heck happened.
Re: Mod Rewrite Rule appending to css js and images paths
Posted: Fri Jan 23, 2009 12:24 am
by s.dot
What probably happened was / was not the intended directory in your localhost. You probably had the site in a subfolder such as /sitename/ and you needed /sitename/style.css.