xampp mod_rewrite在localhost VirtualHost中不起作用

时间:2017-03-16 14:37:15

标签: php apache .htaccess mod-rewrite xampp

我有一个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

1 个答案:

答案 0 :(得分:0)

取消注释rewrite_module modules / mod_rewrite.so之后你重启了apache吗? 如果没有那么重启apache。如果是,请检查在httpd.conf文件中是否包含httpd-vhosts.conf。如果不是这么点吧。

make sur有这个文件夹&#34; fr&#34;在你的项目中。

如果它仍然无法正常工作,我建议您将项目放在xampp文件夹中的htdocs文件夹中。可能存在正确的访问问题。