Why RewriteRule in .htaccess does not have effect?

2019-06-09 09:39发布

问题:

Apache web server is running under Windows 7 professional. Apache version is Apache/2.2.17 (Win32) PHP/5.3.8. mod_rewrite is loaded according to phpinfo(). <VirtualHost> tag contains RewriteLog and RewriteLogLevel 3 directives. Log file set in RewriteLog directive is created.

.htaccess file in root directory is following:

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

Current directory contains bob.html file and it can be opened with localhost URL.

But alice.html URL can not be opened, it causes error 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?

回答1:

Make sure you have this line in your httpd.conf:

AllowOverride All

AllowOverride controls what directives may be placed in .htaccess files.

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.