虚拟主机conf文件重定向添加本地文件路径

发布于 2024-11-09 21:15:56 字数 1167 浏览 0 评论 0原文

我将以下重写添加到我的虚拟主机的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作业与我同在 2024-11-16 21:15:56

根据 文档,您应该在正则表达式中包含本地路径,在分组之前:

RewriteRule ^\/home\/example(.*) http://www.example.com$1 [R=301,L]

同样根据文档:

在第一个 RewriteRule [模式] 上应用
到(%解码的)URL路径
要求;随后的模式是
应用于最后的输出
匹配的重写规则。

这表明您在该规则之前还有其他重写规则。

According to documentation, you should have the local path in the regex, before the grouping:

RewriteRule ^\/home\/example(.*) http://www.example.com$1 [R=301,L]

Also according to the docs:

On the first RewriteRule [the Pattern] is applied
to the (%-decoded) URL-path of the
request; subsequent patterns are
applied to the output of the last
matched RewriteRule.

This would suggest you have other RewriteRules prior to that one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文