使用.htaccess重定向时出现奇怪的错误

时间:2014-10-01 18:51:37

标签: apache .htaccess mod-rewrite hashbang

长话短说我试图重定向:

http://example.com/?_escaped_fragment_=/onetwothree

这样的事情:

http://example.com/serve.php?_escaped_fragment_=/onetwothree

我正在使用以下.htaccess代码:

# Enable Rewriting
RewriteEngine on
RewriteCond %{QUERY_STRING}  _escaped_fragment_=  [NC]
RewriteRule ^(.*)$ http://example.com/serve.php$1 [P,QSA,L]

但反应非常奇怪:

Forbidden

You don't have permission to access /serve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpserve.phpindex.html.var on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

我做错了吗?我是新手。我非常感谢你的帮助。

更新1

我尝试使用:

RewriteEngine on
RewriteCond %{QUERY_STRING}  _escaped_fragment_=  [NC]
RewriteCond $1 ^serve\.php
RewriteRule ^(.*)$ http://example.com/serve.php$1 [P,QSA,L]

但现在它根本不起作用。当我尝试访问example.com/?_escaped_fragment_=/dfas时,它会将我重定向到example.com/?_escaped_fragment_=/dfas#!而不是example.com/serve.php?_escaped_fragment_=dfas请帮助我们,我不知道为什么会发生这种情况。这对我来说非常重要。

1 个答案:

答案 0 :(得分:0)

您需要检查您是否尚未重定向到serve.php:

RewriteEngine on
RewriteCond %{QUERY_STRING}  _escaped_fragment_=  [NC]
RewriteCond $1 !^serve\.php
RewriteRule ^(.*)$ http://example.com/serve.php$1 [P,QSA,L]