简体   繁体   中英

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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM