Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond

         

ucbones

2:30 pm on Sep 15, 2005 (gmt 0)

10+ Year Member



Hi,

I need to rewrite all URLs

domain.com/123

to domain.com/index.php?path=123

Where absolutely anything in place of "123" gets rewritten, except things beginning with "!"

e.g. domain.com/!123 doesn't get rewritten

Or, things with a certain folder name (there's only one of these)

i.e. domain.com/specialfolder doesn't get rewritten

I think it needs to be something like:

RewriteCond %{REQUEST_URI}!= /specialfolder/
RewriteRule (^[^!])* index.php?path=$1

The problem is, that once it's rewritten it once, it then attempts to rewrite the index.php?path=mypath URL, and it goes in an infinite loop- any ideas?

Thanks,

ucbones

dcrombie

2:36 pm on Sep 15, 2005 (gmt 0)



Maybe more like this:

RewriteCond %{REQUEST_URI} !^/specialfolder 
RewriteRule ^([^!].*) /index.php?path=$1

;)

jdMorgan

3:30 pm on Sep 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And add an exclusion for index.php itself:

RewriteCond %{REQUEST_URI}!^/specialfolder
RewriteCond %{REQUEST_URI}!^/index\.php$
RewriteRule ^([^!].*) /index.php?path=$1

Mod_rewrite in .htaccess context behaves recursively, because the server must rerun all URL-based modules after any rewrite in order to check for access restrictions and further rewrites on the newly-rewritten URL-path. Therefore, looping must be explicitly prevented.

Jim

ucbones

5:10 pm on Sep 15, 2005 (gmt 0)

10+ Year Member



Hi,

Thanks for your help, but I'm getting a 500 internal server error when I try that, jdmorgan.

I tried:


RewriteCond %{REQUEST_URI}!^/specialfolder
RewriteCond %{REQUEST_URI}!^/index\.php$
RewriteRule ^([^!].*) /index.php?path=$1

On the second line, did you mean SCRIPT_NAME in place of REQUEST_URI? I tried both and neither worked, but SCRIPT_NAME seems more accurate, as REQUEST_URI would never end in .php (as the path gets appended on line 3).

I have turned mod_rewrite on!

Any more ideas?

ucbones

jd01

7:26 pm on Sep 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On the second line, did you mean SCRIPT_NAME in place of REQUEST_URI? I tried both and neither worked, but SCRIPT_NAME seems more accurate, as REQUEST_URI would never end in .php (as the path gets appended on line 3).

Apache does not 'see' the query_string in mod_rewrite, unless explicitly told to do so using the Condition %{QUERY_STRING}, so the request URI of /index.php?anything=anything will *always* end in index.php.

I would try:

RewriteCond %{REQUEST_URI} !^/specialfolder
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^([^!]+) /index.php?path=$1 [L]

And if you cannot get that to work, you could always just work around it (not ideal):

RewriteRule ^(index\.php)¦(specialfolder) - [L]
RewriteRule ^([^!]+) /index.php?path=$1 [L]

Justin