我将以下重写添加到我的虚拟主机的conf文件中:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
.... A bunch of aliases here
该网站与www合作正常。但如果你进入没有www的域名。该网站将重定向到www.example.com/home/example/public_html - 它会添加文件路径。我该如何防止这种情况?
这是别名:
Alias /index.php /home/cms/public/index.php
Alias /skins/admin /home/cms/public/skins/admin
AliasMatch ^/scripts/(\w+)/admin/(\w+)\.js /home/cms/modules/$1/scripts/admin/$2.js
AliasMatch ^/scripts/(\w+)/(\w+)\.js /home/cms/modules/$1/scripts/$2.js
Alias /scripts /home/cms/public/scripts
AliasMatch (?i)^/flash/([A-Za-z]*)/([A-Za-z_]*).swf$ /home/cms/public/flash/$1/$2.swf
Alias /css /home/cms/public/css
Alias /thirdparty /home/cms/public/thirdparty
RewriteEngine off
<Directory /home/cms>
Order allow,deny
Allow from all
</Directory>
<Location />
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
</Location>
答案 0 :(得分:0)
根据documentation,在分组之前,你应该在正则表达式中有本地路径:
RewriteRule ^\/home\/example(.*) http://www.example.com$1 [R=301,L]
另据文档说明:
在第一个RewriteRule [Pattern]上应用 到(% - 解码)的URL路径 请求;后续的模式是 应用于最后的输出 匹配RewriteRule。
这表明你在那之前还有其他的RewriteRules。