rewrite_mod已启用,但的.htaccess不工作
我在Amazon EC2上使用Apache 2.2在Ubuntu 12.04。 我启用了mod_rewrite使用
I am using apache 2.2 in ubuntu 12.04 in Amazon EC2. I enabled mod_rewrite using
sudo a2enmod rewrite
和能看到
apache2ctl -M
现在我写的.htaccess code如下,并不能正常工作
now I wrote the .htaccess code as following and is not working
# Redirect everything in this directory to "good.html"
Options +FollowSymlinks
RewriteEngine on
RewriteRule .* good.html
下面是在/ etc / apache2的/站点可用/默认我的内容 http://pastebin.com/urNfmqan
Here is my contents of /etc/apache2/sites-available/default http://pastebin.com/urNfmqan
当我添加
的LoadModule rewrite_module模块/ mod_rewrite.so
来我得到这个在httpd.conf
等待[星期四年04月11 18点44分12秒2013] [提醒]模块rewrite_module已经加载,跳绳
和htaccess的不工作,甚至然后(我presume中的Apache2 0.2我们不修改httpd.conf文件,使rewrite_mod但按anubhava评论我修改的问题)
when I add
LoadModule rewrite_module modules/mod_rewrite.so
to the httpd.conf I get this
waiting [Thu Apr 11 18:44:12 2013] [warn] module rewrite_module is already loaded, skipping
and htaccess is not working even then ( I presume in apache2.2 we don't edit httpd.conf to enable rewrite_mod but as per anubhava comments I modified the question)
看起来你将有一个重写循环。 Apache的重写不能用于路径要求每次运行规则一次,但一次。因此,在第一次加载它重写。*
到 good.html
。然后,它使内部要求 good.html
并重新处理规则一而再,再重写,使另一内部请求到无穷远。 r事件的回答试图通过检查文件是否存在解决这个问题。你得到 index.html的
在他的规则,因为 index.html的
的存在。如果删除 index.html的
文件将不存在,则重写条件将匹配的规则将重写 good.html
。 ,该文件存在,条件不满足时再处理规则,之后重定向停止。
Looks like you will have a rewrite loop. Apache rewrite doesn't run the rules once, but once for every time a path is requested. So on first load it rewrites .*
to good.html
. Then it makes an internal request for good.html
and re-processes the rules again, rewriting again and makes another internal request to infinity. Revent's answer tries to solve this by checking if the file exists. You get index.html
in his rules because index.html
exists. If you removed index.html
the file wouldn't exist, the rewrite condition would match and the rule would rewrite to good.html
. When re-processing the rules, the file exists, the condition fails and redirect stops after that.
要解决,你可以在你的重写规则的后面添加 [L]
标记告诉Apache停止处理规则这一运行应停止循环后。如果没有帮助,您可以添加一个的RewriteCond
来检查 REQUEST_FILENAME
不是 good.html
从而导致规则重定向后失败。
To fix, you can add the [L]
flag after your rewrite rule to tell apache to stop processing rules after this one runs which should stop the loop. If that doesn't help, you can add a rewriteCond
to check that the request_filename
is not good.html
causing the rule to fail after redirect.