虚拟主机conf文件重定向添加本地文件路径
我将以下重写添加到我的虚拟主机的 conf 文件中:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
.... A bunch of aliases here
该站点与 www.conf 文件兼容。但如果你输入的域名没有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>
I'm adding the following rewrite to the conf file for my virtual host:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
.... A bunch of aliases here
The site works fine with the www. but if you enter the domain without the www. the site will be redirected to www.example.com/home/example/public_html - it adds the file path. How can I prevent this?
Here's the aliases:
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 文档,您应该在正则表达式中包含本地路径,在分组之前:
同样根据文档:
这表明您在该规则之前还有其他重写规则。
According to documentation, you should have the local path in the regex, before the grouping:
Also according to the docs:
This would suggest you have other RewriteRules prior to that one.