Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

apache - Htaccess Redirect URL with two forward slashes (not double) won't work

I want to redirect from one domain to a new domain. At the same time, the URL structure has changed.

  • Old: https://www.olddomain.com/parentpage/oldtitle/
  • New: https://www.newdomain.com/newtitle

This is wordpress, and I placed this code above the Wordpress stuff, as well as tested it here: https://htaccess.madewithlove.be/

  1. I tried this, which doesn't work:

    Redirect 301 /parentpage/title https://www.newdomain.com/newtitle
    
  2. Also, when testing it at https://htaccess.madewithlove.be/, I do have this redirect:

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

    The tester would skip my preferred redirect above, and use this one, leaving me with this, which does not exist:

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

    Even when I place the preferred redirect above this one. I need both, unfortunately.

  3. Have also tried the following RewriteRules (not all at the same time)

    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"
    

I think it has something to do with that second forward slash separating the parentpage name and page title, but I can't figure out how to fix it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In RewriteRule it wouldn't match http or https in it, you may try following.

please make sure you clear your browser cache before testing your URLs.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...