简体   繁体   中英

mod_rewrite is not working

i am using xampp on windows.For last two days i am trying to rewrite URL's but mod rewrite is doing nothing.its taking me to the same page.i am trying to do a simple redirect from foo.html to bar.html as its is an example rewrite docs. I have put all the directives in .htaccess.

.htaccess is processing cause adding something like "blah blah blah" in it results in 500 internal server error . here are lines in my .htaccess file.

RewriteEngine On
RewriteRule ^/foo.html /bar.html [R]

I enabled logging and here is what it is telling me for my last request for foo.html at trace3.

[Sat Jun 14 12:00:49.125000 2014] [rewrite:trace3] [pid 5116:tid 8]    mod_rewrite.c(475): [client 127.0.0.1:4656] 127.0.0.1 - - [localhost/sid#9006d0][rid#9dd270/initial] [perdir D:/x3/htdocs/] strip per-dir prefix: D:/x3/htdocs/foo.html -> foo.html

[Sat Jun 14 12:00:49.125000 2014] [rewrite:trace3] [pid 5116:tid 8] mod_rewrite.c(475): [client 127.0.0.1:4656] 127.0.0.1 - - [localhost/sid#9006d0][rid#9dd270/initial] [perdir D:/x3/htdocs/] applying pattern '^/foo.html' to uri 'foo.html'

[Sat Jun 14 12:00:49.125000 2014] [rewrite:trace1] [pid 5116:tid 8] mod_rewrite.c(475): [client 127.0.0.1:4656] 127.0.0.1 - - [localhost/sid#9006d0][rid#9dd270/initial] [perdir D:/x3/htdocs/] pass through D:/x3/htdocs/foo.html

[Sat Jun 14 12:00:49.531250 2014] [rewrite:trace3] [pid 5116:tid 8] mod_rewrite.c(475): [client 127.0.0.1:4656] 127.0.0.1 - - [localhost/sid#9006d0][rid#55020a8/initial] [perdir D:/x3/htdocs/] strip per-dir prefix: D:/x3/htdocs/favicon.ico -> favicon.ico

[Sat Jun 14 12:00:49.531250 2014] [rewrite:trace3] [pid 5116:tid 8] mod_rewrite.c(475): [client 127.0.0.1:4656] 127.0.0.1 - - [localhost/sid#9006d0][rid#55020a8/initial] [perdir D:/x3/htdocs/] applying pattern '^/foo.html' to uri 'favicon.ico'

[Sat Jun 14 12:00:49.531250 2014] [rewrite:trace1] [pid 5116:tid 8] mod_rewrite.c(475): [client 127.0.0.1:4656] 127.0.0.1 - - [localhost/sid#9006d0][rid#55020a8/initial] [perdir D:/x3/htdocs/] pass through D:/x3/htdocs/favicon.ico

i have no idea of what is wrong?:(

please help me out. i have successfully used mod_rewrite in the past but have no idea what is it that i am doing wrong.

I figured it out. I changed lines in my .htaccess from

RewriteEngine On

RewriteRule ^/foo.html /bar.html [R]

to

RewriteEngine on

RewriteRule ^foo\.html /bar.html [R]

And now it's working fine.

I guess this was happening because '/' is automatically added in .htaccess and I was also including a trailing slash so no match was found By RewriteRule and hence it was not doing anything.

but this was not the case or httpd.conf. also, rewriteBase is important here in some way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM