【问题标题】:Htaccess Redirect URL with two forward slashes (not double) won't work带有两个正斜杠(不是双斜杠)的 Htaccess 重定向 URL 不起作用
【发布时间】:2020-12-31 22:46:48
【问题描述】:

我想从一个域重定向到一个新域。同时,URL 结构也发生了变化。

  • 老:https://www.olddomain.com/parentpage/oldtitle/
  • 新:https://www.newdomain.com/newtitle

这是 wordpress,我将这段代码放在了 Wordpress 的上面,并在这里进行了测试:https://htaccess.madewithlove.be/

  1. 我试过了,还是不行:

    Redirect 301 /parentpage/title https://www.newdomain.com/newtitle
    
  2. 另外,在https://htaccess.madewithlove.be/ 测试它时,我确实有这个重定向:

    Redirect 301 /parentpage https://www.newdomain.com/parentpage
    

    测试人员会跳过我上面的首选重定向,并使用这个,给我留下这个,它不存在:

    https://www.newdomain.com/parentpage/oldtitle
    

    即使我将首选重定向放在此重定向之上。不幸的是,我两个都需要。

  3. 也尝试过以下 RewriteRules(不是同时尝试)

    ReWriteRule https://www.olddomain.com/parentpage/oldtitle/ https://www.newdomain.com/newtitle
    ReWriteRule /parentpage/oldtitle/ https://www.newdomain.com/newtitle
    ReWriteRule "https://www.olddomain.com/parentpage/oldtitle/" "https://www.newdomain.com/newtitle"
    

我认为这与分隔父页面名称和页面标题的第二个正斜杠有关,但我不知道如何解决它。

【问题讨论】:

  • “两个正斜杠(不是双)”是什么意思? “不加倍”是什么意思?
  • 对不起,我在google的时候,这里有很多话题,所以我选择在这里发帖。当我尝试搜索我的问题(google、here、reddit 等)时,搜索结果通常会返回一个不同的问题,即用户在使用带有两个或更多双斜杠的 URL 时遇到问题,例如:www.domain.com//title

标签: apache .htaccess redirect mod-rewrite url-rewriting


【解决方案1】:

RewriteRule 里面的 http 和 https 不匹配,你可以试试。

请确保在测试 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)olddomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/parentage/oldtitle/?$ [NC]
RewriteRule ^(.*)$ https://www.newdomain.com/newtitle [R=301,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    相关资源
    最近更新 更多