Forum Moderators: phranque

Message Too Old, No Replies

simple rewrite rule + relative paths =

browser doesn't load resources

         

Grimmjow

9:53 pm on Jun 15, 2008 (gmt 0)

10+ Year Member



I'll try to make it fast.

My test local site folder structure:

d:\sites\example\.
d:\sites\example\css\.
d:\sites\example\js\.
d:\sites\example\images\.
...

In the browser:

[localhost...]

.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>

If I link stuff (css, js, jpg, ...) such as:

<link rel="stylesheet" href="css/style.css" type="text/css" />

When .htaccess is in place, the resource is not found, the css is not loaded. The whole site seems to take forever to load, I think Apache has entered in a loading loop. I see raw text, without style applied, no images too.

Instead if I use a url like:

<link rel="stylesheet" href="/example/css/style.css" type="text/css" />

It works. (If I deactivate/move/rename away .htaccess, all works perfectly even without the /example/ prefix)

Is there a particular reason to explain this behaviour? Why should I use complete url such as /example/.../resource.ext ? I'm not a mod_rewrite expert, so the issue could be in there.

Thanks for reading so far.

g1smd

10:10 pm on Jun 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The browser resolves the URL. So, start the URL with a / and the browser should then know where to look.

However, your rewrite rewrites for all file types, so you might want to alter it to only rewrite for .html filetypes.

jdMorgan

2:24 am on Jun 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A list of paths and filetypes you need to decide whether to rewrite or not:

/robots.txt
custom error pages
/sitemap.xml
/w3c/p3p.xml
/labels.rdf (or .xml)
images & media files
external css
external JavaScript files
.pdf documents (or others)
search engine tools "authorization key" files

Using an explicit exclusion list can be far more efficient than simply checking to see if the requested URL resolves to an existing file or directory. It can also greatly reduce the amount of error handling that the script needs to do, because as it stands now, the script is solely responsible for determining whether to return a 200-OK status response, a 301, 302, or 303 redirect, a 404-Not Found, or a 410-Gone.

The explicit exclusion list prevents the server having to call the OS to go check the filesystem twice for each and every HTTP request made to your server. This can significantly impact server performance on a busy site -- or on a site that shares a server with other busy sites.

Jim

Grimmjow

8:29 am on Jun 16, 2008 (gmt 0)

10+ Year Member



Thanks very much.

[edited by: Grimmjow at 8:30 am (utc) on June 16, 2008]