rule appears to be ignoring rewrite condition

Discuss practical ways rearrange URLs using mod_rewrite.

rule appears to be ignoring rewrite condition

Postby darkrose0510 » Thu Oct 16, 2008 3:54 am

Hello,

I've been trawling this forum for a while now whenever I get problems with mod rewrite, but this is the first problem I haven't been able to solve.

I have a relatively simple rewrite rule which basically takes any request not directed to one of a few selected files, and sends the request to /index.php

RewriteEngine on
RewriteCond %{REQUEST_URI} !=/init.js
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !=/ajax.php
RewriteCond %{REQUEST_URI} !=/file.php
RewriteCond %{REQUEST_URI} !=/img.php
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^\.*$ /index.php [L]


It works, mostly.

every page loads /init.js and this is where the problems come in.
If I go to / it works fine.
If I go to /home or /blog it works fine.

But once I get more then one 'directory' deep, such as /blog/darkrose /init.js gets pointed to /index.php and hence my javascript doesn't get loaded.

The src value of the script tag is an absolute path "/init.js" not "init.js", but the problem is still occuring.

Any ideas?
darkrose0510
 
Posts: 2
Joined: Thu Oct 16, 2008 3:38 am

Postby richardk » Thu Oct 16, 2008 6:58 am

But once I get more then one 'directory' deep, such as /blog/darkrose /init.js gets pointed to /index.php and hence my javascript doesn't get loaded.

The src value of the script tag is an absolute path "/init.js" not "init.js", but the problem is still occuring.

Have you cleared your browser's cache? Are you sure the correct request is being made? Check the request headers with something like the Live HTTP Headers plug-in for Firefox.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(init\.js|index\.php|ajax\.php|file\.php|img\.php|favicon\.ico)$ [NC]
RewriteRule .* /index.php [L]

Try removing the $ from the RewriteCond if it still doesn't work.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby darkrose0510 » Fri Oct 17, 2008 4:05 am

Thanks richardk,

That Live HTTP Headers is a handy little plugin, it showed the page was 404 not found (which redirects to index.php where php parses it as normal - hence why I couldn't see the problem). I removed the $ from the rule and it's working fine now.
darkrose0510
 
Posts: 2
Joined: Thu Oct 16, 2008 3:38 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 17 guests

cron