简体   繁体   English

为什么.htaccess中的RewriteRule不起作用?

[英]Why RewriteRule in .htaccess does not have effect?

Apache web server is running under Windows 7 professional. Apache Web服务器在Windows 7 Professional下运行。 Apache version is Apache/2.2.17 (Win32) PHP/5.3.8. Apache版本是Apache / 2.2.17(Win32)PHP / 5.3.8。 mod_rewrite is loaded according to phpinfo() . mod_rewrite根据phpinfo()加载。 <VirtualHost> tag contains RewriteLog and RewriteLogLevel 3 directives. <VirtualHost>标记包含RewriteLogRewriteLogLevel 3指令。 Log file set in RewriteLog directive is created. 创建在RewriteLog指令中设置的日志文件。

.htaccess file in root directory is following: 根目录中的.htaccess文件如下:

RewriteEngine  On
RewriteRule ^alice\.html$ bob.html

Current directory contains bob.html file and it can be opened with localhost URL. 当前目录包含bob.html文件,可以使用localhost URL打开它。

But alice.html URL can not be opened, it causes error 404. 但是alice.html URL无法打开,它导致错误404。

Log file for this site contains just normal message about file not found. 该站点的日志文件仅包含有关找不到文件的普通消息。

Rewrite log file exists but empty. 重写日志文件存在但为空。

Which can cause rewrite directives being ignored? 哪些会导致重写指令被忽略?

Make sure you have this line in your httpd.conf: 确保您的httpd.conf中包含以下行:

AllowOverride All

AllowOverride controls what directives may be placed in .htaccess files. AllowOverride控制可以在.htaccess文件中放置哪些指令。

Testing: To test whether .htaccess is enabled or not, just put some junk text in it and see if it generated a 500 internal error or not. 测试:要测试.htaccess是否已启用,只需在其中放入一些垃圾文本,然后查看它是否产生了500个内部错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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