2014-06-14 103 views
0

我在Windows上使用xampp。最近两天我试图重写URL的,但是mod重写没有做任何事情。我把我带到同一页面。我试图从foo做一个简单的重定向。 html为bar.html,因为它是一个重写文档的例子。 我已经把所有的指令放在.htaccess中。mod_rewrite无法正常工作

htaccess的正在处理的原因添加类似“等等等等等等”在它导致500内部服务器错误。 这里是我的.htaccess文件中的行。

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

我启用了日志功能,这是它告诉我我在trace3上最后一次请求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/] 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 

我不知道什么是错误的想法?:(

请帮助我。我 已经成功使用mod_rewrite的过去,但不知道它是什么,我做错了。

+0

将相同的行添加到httpd.conf中Works.Weired。 –

+0

我的服务器conf's.没有任何问题,我试图把这些行放到我的主机帐户中,他们甚至在那里都不工作。不知道该怎么办。它不是我第一次使用这个mod_rewrite.It使用之前工作正常。 –

+0

日志第二行告诉您从模式中删除正斜杠。在那里避开点'\'。 – Deadooshka

回答

1

我fiured它out.:-D 我在的.htaccess改线从

RewriteEngine On 

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

RewriteEngine on 

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

现在它的工作正常。

我想这是因为'/'被自动添加到.htaccess中,我还包括一个尾部的斜线,所以没有找到匹配的RewriteRule,因此它没有做任何事情。

但这不是这种情况或httpd.conf。 rewriteBase在某些方面很重要。

我怎么不知道。但可能有一天我会:-D