【问题标题】:Please take a look at this .htaccess file请看一下这个 .htaccess 文件
【发布时间】:2013-08-22 08:37:27
【问题描述】:

我正在尝试使用 .htaccess 文件中的重写脚本为托管在 Apache 服务器 (Fasthosts) 上的站点上的子页面实现 301。我尝试遵循许多文档(事实上,我之前使用 .htaccess 实现 301 从未遇到任何问题!)但在这个特定的网站上,似乎没有任何效果。

目前有一个从非 www 到 www 的 301 重定向,工作正常。还有一些其他使用正则表达式的 sn-ps,我想它们是用于 CMS 的。

以下是 .htaccess 文件的当前状态。我尝试重定向的 301 示例在其中(第 5 行和第 6 行)

旧页面:http://www.junkwize.com/home-Garden%20Clearance 到新页面:http://www.junkwize.com/services/garden-clearance-london

.htaccess 文件:

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

RewriteCond %{HTTP_HOST} www.junkwize.com/home-Garden%20Clearance
RewriteRule (.*) http://www.junkwize.com/services/garden-clearance-london [R=301]

#Options +FollowSymlinks
RewriteRule ^.htaccess$ — [F]

RewriteRule ^([/admin]+)$ admin/login.php [L]
RewriteRule ^([/admin]+)([/blocks]+)$ admin/login.php [L]

RewriteRule ^([/blocks]+)$ index.php [L]
# RewriteRule ^([^/\.]+)-([^/\.]+)-([^/\.]+)$ index.php?main=$1&id=$2&menu=$3 [L]
RewriteRule ^([/deals]+)-([^/\.]+)$ index.php?main=$1&id=$2 [L]

# RewriteRule ^([^/\.]+)-([^/\.]+)$ index.php?main=$1&leftmain=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)$ index.php?main=$1&leftmain=$2 [L]
RewriteRule ^([^/\.]+)$ index.php?main=$1 [L]

任何帮助将不胜感激。

非常感谢。

【问题讨论】:

    标签: .htaccess mod-rewrite http-status-code-301


    【解决方案1】:

    此代码有问题,无法正常工作:

    RewriteCond %{HTTP_HOST} www.junkwize.com/home-Garden%20Clearance
    RewriteRule (.*) http://www.junkwize.com/services/garden-clearance-london [R=301]
    

    原因是RewriteCond %{HTTP_HOST} 只能匹配主机名。用这个替换那个代码:

    RewriteRule ^home-Garden\ Clearance/?$ /services/garden-clearance-london [R=301,L,NC]
    

    【讨论】:

    • 谢谢@anubhava ...我已将:RewriteCond %{HTTP_HOST} www.junkwize.com/home-Garden%20Clearance RewriteRule (.*) http://www.junkwize.com/services/garden-clearance-london [R=301] 替换为:RewriteRule ^home-Garden%20Clearance/?$ /services/garden-clearance-london [R=301,L,NC] 仍然没有运气。会不会还有其他问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    相关资源
    最近更新 更多