Forum Moderators: phranque

Message Too Old, No Replies

Apache 2.0 Windows mod_rewrite error

         

LoganK

2:44 pm on Aug 2, 2005 (gmt 0)

10+ Year Member



I've got Apache 2.x (I know it's something with a "2.") running on Windows, and mod_rewrite is running fine with this example:

RewriteEngine on
RewriteRule ^old\.html$ new.html
RewriteRule ^([0-9]+)$ index.php?id=$1
RewriteRule ^([0-9]+)/$ index.php?id=$1

However, I've seen that repeating the same condition like that (without the slash) isn't good - instead, do a redirect:

RewriteEngine on
RewriteRule ^old\.html$ new.html
RewriteRule ^([0-9]+)$ $1/ [R]
RewriteRule ^([0-9]+)/$ index.php?id=$1

This should do something like redirect localhost/42 to localhost/42/, at which point the second re-write rule will take place, transparently re-writing to index.php?id=42. However, with the "[R]" modifier, it instead redirects to "http://localhost/C:/Apache/Apache2/htdocs/42". Anyone know what's wrong with this?

ChadSEO

5:44 pm on Aug 2, 2005 (gmt 0)

10+ Year Member



I haven't heard anything about using the same condition, but then I'm a relative newcomer to mod_rewrite. As far as the issue with the second set of rewrites, try adding the following line below "RewriteEngine On":

RewriteBase /

LoganK

9:17 pm on Aug 2, 2005 (gmt 0)

10+ Year Member



Yes, RewriteBase worked. I had done some research and after looking at the documentation that was written back in 1996 (!) (I'm surprised it's still correct!), I got it working. Thanks!