我正在使用运行PHP 5.6的Apache 2.4 httpd服务器
我已删除对以下内容的注释,在httpd.conf
文件夹中启用了mod_rewrite:
LoadModule rewrite_module modules/mod_rewrite.so
我已将.htaccess文件添加到我的服务器目录以及虚拟主机目录。
服务器目录位于httpd.conf
文件中,如下所示:
DocumentRoot "c:/web"
<Directory "c:/web">
DirectoryIndex index.html index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Allow from All
</Directory>
在我httpd-vhosts.conf
我有以下内容:
ServerName localhost
DocumentRoot "c:\web"
<VirtualHost *:80>
<Directory "c:\web">
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
ServerName localhost
ServerAlias localhost
DocumentRoot "c:\web"
</VirtualHost>
<VirtualHost *:80>
ServerName Personal.localhost
ServerAlias Personal.localhost
DocumentRoot "C:\personal\web"
DirectoryIndex index.html index.php
<Directory "C:\personal\web">
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
我知道Apache服务器会加载.htaccess
文件,因为如果我将损坏的代码添加到文件中,我会得到500 Internal Server Error
(当破解的代码位于顶部或底部时,它会执行此操作页。)
我的.htaccess
文件如下所示:
IndexIgnore * # prevent directory listing
Order deny,allow
Allow from *
# ------------------------------------------
# Hide the PHP extentions
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
# ------------------------------------------
# This should set cache for all items
<IfModule mod_headers.c>
<FilesMatch "\.(jpg|jpeg|png|gif|swf|mp3|avi|js|css|html|php)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</IfModule>
# ------------------------------------------
# Compress data
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
在access.log
文件中,我可以看到请求,但不会将.php
扩展名添加到网址末尾:
DeveloperUsr - - [27/Jan/2016:15:12:44 +0200] "GET /admin/login HTTP/1.1" 404 209
error.log
文件包含以下内容:
[Wed Jan 27 15:12:44.324658 2016] [negotiation:error] [pid 18324:tid 1084] [client ::1:50784] AH00687: Negotiation: discovered file(s) matching request: C:/Personal/web/admin/login (None could be negotiated).
我该怎么做才能启用.htaccess
或网址重写。我知道.htaccess
文件有效,因为如果我将服务器加载到Linux生产环境,它就会加载并运行。我无法访问生产环境的配置文件,因此我看不出配置文件有什么问题。
答案 0 :(得分:1)
如果您依靠mod_rewrite以这种方式进行映射,请禁用MultiView。