【发布时间】:2017-08-07 19:21:39
【问题描述】:
我有一个 VirtualHost local.mywebsite.com ,我使用重写规则 在我的 .htaccess 文件中
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteCond %{QUERY_STRING} (\"|%22).*(<|>|%3) [NC,OR]
RewriteCond %{QUERY_STRING} (javascript:).*(\;) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3) [NC,OR]
RewriteCond %{QUERY_STRING} (\;|\'|\"|%22).*(union|select|insert|drop|update|md5|benchmark|or|and|if) [NC,OR]
RewriteCond %{QUERY_STRING} (base64_encode|localhost|mosconfig) [NC,OR]
RewriteCond %{QUERY_STRING} (boot\.ini|echo.*kae|etc/passwd) [NC,OR]
RewriteCond %{QUERY_STRING} (GLOBALS|REQUEST)(=|\[|%) [NC]
RewriteRule .* - [E=BadQueryString,F]
RewriteRule ^ - [E=BASE:{DOCBASE}] [L]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTPS}:s on:(s)
RewriteRule ^(.*)$ http%1://local.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} /admin/
RewriteRule .* - [S=2]
RewriteRule ^(.*)index\.php$ %{ENV:BASE}$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9!-/]*)$ %{ENV:BASE} [L]
在 httpd-vhosts.conf 中
<VirtualHost *:80>
DocumentRoot "E:/websites/local.mywebsite.com"
ServerName local.mywebsite.com
<Directory "E:/websites/local.mywebsite.com">
# AllowOverride All # Deprecated
# Order Allow,Deny # Deprecated
# Allow from all # Deprecated
AllowOverride All
# --New way of doing it
Require all granted
</Directory>
在 httpd.conf 中
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
我取消注释 LoadModule rewrite_module modules/mod_rewrite.so
但是 local.mywebsite.com/fr 返回错误 404
【问题讨论】:
-
你在 httpd.conf 中取消了
LoadModule rewrite_module modules/mod_rewrite.so的注释吗? -
我在 Windows 中,所以我通过编辑 httpd 文件手动完成并取消注释 LoadModule rewrite_module modules/mod_rewrite.so
标签: php apache .htaccess mod-rewrite xampp