我想从一个域重定向到一个新域。与此同时,URL结构也发生了变化。
- 旧:
https://www.olddomain.com/parentpage/oldtitle/
- 新增:
https://www.newdomain.com/newtitle
这是wordpress,我把这段代码放在wordpress的东西上面,并在这里测试了它:https://htaccess.madewithlove.be/
-
我试过这个,但不起作用:
Redirect 301 /parentpage/title https://www.newdomain.com/newtitle
-
此外,在https://htaccess.madewithlove.be/,我确实有这个重定向:
Redirect 301 /parentpage https://www.newdomain.com/parentpage
测试人员会跳过上面我喜欢的重定向,并使用这个,留给我这个,它不存在:
https://www.newdomain.com/parentpage/oldtitle
即使我将首选重定向放置在此重定向之上。不幸的是,我两者都需要。
-
还尝试过以下重写规则(并非同时进行(
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"
我认为这与分隔父页面名称和页面标题的第二个正斜杠有关,但我不知道如何修复它。
在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]