Forum Moderators: phranque

Message Too Old, No Replies

Bootstrapping help

.htaccess RewriteRule acts oddly

         

valleyds

3:50 am on Feb 8, 2008 (gmt 0)

10+ Year Member



If this is a dumb question forgive me but I am not having much luck with this. I am trying to create a bootstrap file and using .htaccess to send all pages through my index.php file. Currently I have:

RewriteEngine on
RewriteRule!\.(js¦ico¦gif¦jpg¦png¦css)$ index.php

and that works only somtimes. If I view my site through http://www.example.org or http://www.example.org/ it gives me a 500 error. However if I go to http://www.example.org/index.php it will work, or if I set it up as subdomain http://example.sitehost.org it will work. I am not sure what I am doing wrong, everywhere i have looked has some sort of variation of this rewrite rule and none seem to fix this.

Dan

jdMorgan

2:26 pm on Feb 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your rule will rewrite index.php to itself repeatedly until the server's internal redirection limit is reached. Add a RewriteCond to prevent this looping:

RewriteCond %{REQUEST_URI} !/index\.php$
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css)$ index.php [L]

or alternately, the rather ungainly-looking method:

RewriteRule !(\.(js¦ico¦gif¦jpg¦png¦css)¦^index\.php)$ index.php [L]

Also consider what your code should do with requests for "robots.txt", "sitemap.xml", "/w3c/p3p.xml", and other "Web-standard" files -- Do you want those rewritten to your script? -- Probably not.

Replace all broken pipe "¦" characters with solid pipes before use; Posting on this forum modifies the pipe characters.

Jim

valleyds

3:04 am on Feb 9, 2008 (gmt 0)

10+ Year Member



Hey, thanks for the response, that fixed the problem.

Dan