【问题标题】:Redirect www to non-www with site installed in subfolder将 www 重定向到非 www,站点安装在子文件夹中
【发布时间】:2017-08-26 15:33:29
【问题描述】:

编辑:原来是 DNS 配置问题。我看不到它,因为它在主机端配置不正确,并且在我端没有显示为损坏。对于遇到相同问题的任何人,请尝试 ping 您的网站 - 如果 ping 通过一个而不是另一个(www 或非 www),请使用 MxTools 或其他工具检查您的 DNS 配置。

我在 public_html/subfolder 中安装了一个位于 site.com.au 的 Joomla 网站

重定向可以正常工作以从 url 中删除 /subfolder,但我不能让它与 www 重定向到非 www 一起使用。访问 site.com.au 有效,访问 www.site.com.au 超时。我给网络主机(Crazy Domains)打了电话,那家伙花了 20 分钟试图弄明白,但还是搞不定。

当前的 htaccess 如下所示:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?site\.com\.au$ [NC]
RewriteCond %{REQUEST_URI} !/subfolder/
RewriteRule (.*) /subfolder/$1 [L]

RewriteCond %{HTTP_HOST} ^www\.site\.com\.au$ [NC]
RewriteRule ^(.*)$ http://site.com.au/$1 [L,R=301]

我也试过了

RewriteEngine on

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{THE_REQUEST} subfolder/
RewriteRule ^subfolder/(.*) http://site.com.au/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !subfolder/
RewriteRule ^(.*)$ /subfolder/$1 [L]

【问题讨论】:

    标签: .htaccess redirect web


    【解决方案1】:

    试试这个

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.example\.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    

    应该有帮助

    【讨论】:

    • 不,那没用。我的 htaccess 现在是 'RewriteEngine on RewriteCond %{HTTP_HOST} ^(www\.)?example\.com\.au$ [NC] RewriteCond %{REQUEST_URI} !/subdir/ RewriteRule (.*) /subdir/$1 [L ] RewriteCond %{HTTP_HOST} !^www\.example\.com\.au$ RewriteRule (.*) example.com.au/$1 [R=301,L]'
    【解决方案2】:

    原来是 DNS 配置问题。我看不到它,因为它在主机端配置不正确,并且在我端没有显示为损坏。对于遇到相同问题的任何人,请尝试 ping 您的网站 - 如果 ping 通过一个而不是另一个(www 或非 www),请使用 MxTools 或其他工具检查您的 DNS 配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 1970-01-01
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多