【问题标题】:Forwarding Old URL with trailing slash转发带有斜杠的旧 URL
【发布时间】:2021-04-07 04:41:22
【问题描述】:

我使用 Divi builder 和 WordPress 来构建我的网站已经有一段时间了。我超越了它并切换到 Webflow,以便更容易实现自定义代码。我已经让网站上线了,但是有一个大问题......

Divi Builder 创建的 URL 看起来像这样

https://hike2hike.com/eldorado-peak-climb-washington/

现在我的主机服务器上有所有站点文件,我得到的 URL 看起来像这样

https://hike2hike.com/eldorado-peak-climb-washington.html 缺少尾部斜杠并添加了 .HTML

并且缺少尾部斜杠。

我已使用以下代码编辑了 .htaccess 文件:

# Remove trailing slash from non-filepath urls
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ https://www.hike2hike.com/%1 [R=301,L]

# Include trailing slash on the directory 
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ https://www.hike2hike.com/$1/ [R=301,L]

# Force HTTPS and WWW 
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [OR,NC]
RewriteCond %{https} off  
RewriteRule ^(.*)$ https://www.hike2hike.com/$1 [R=301,L]

但是,当我尝试使用旧链接进入网站时,我仍然收到服务器错误。

关于如何将旧 URL 转移到新站点 URL 的任何想法,这样我就不会失去 5 年来建立的所有 SEO?

【问题讨论】:

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


    【解决方案1】:

    很好的尝试,恕我直言,我相信您几乎做对了,您需要将 https 强制规则放在 htaccess 的顶部,否则它将完全重定向 URL;在检查 uri 是否以 / 结尾的最后一条规则中更正了您的正则表达式,请您尝试一次。公平的警告,我目前无法对其进行测试。

    放置此 .htaccess 文件后,请确保在测试 URL 之前清除浏览器缓存。

    # Force HTTPS and WWW 
    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [OR,NC]
    RewriteCond %{https} off  
    RewriteRule ^(.*)$ https://www.hike2hike.com/$1 [R=301,L]
    
    
    # Remove trailing slash from non-filepath urls
    RewriteCond %{REQUEST_URI} ^/(.+)/$
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ https://www.hike2hike.com/%1 [R=301,L]
    
    
    # Include trailing slash on the directory 
    RewriteCond %{REQUEST_URI} !/$
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.+)$ https://www.hike2hike.com/$1/ [R=301,L]
    

    【讨论】:

    猜你喜欢
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    相关资源
    最近更新 更多