Forum Moderators: phranque
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
RewriteCond %{REQUEST_URI} !^/specialfolder
RewriteRule ^([^!].*) /index.php?path=$1 ;)
RewriteCond %{REQUEST_URI}!^/specialfolder
RewriteCond %{REQUEST_URI}!^/index\.php$
RewriteRule ^([^!].*) /index.php?path=$1
Jim
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
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