Ad

301 Redirect From Http To Https And New Page Name

- 1 answer

I have a site that is going from a non secure HTML/PHP site to a secure Wordpress site. All pages are changing. Also going from www to non-www.

So as an example

http://www.sitename.com/contact.php

will become

https://sitename.com/contact-us/

I know how to do a typical redirect in .htaccess:

Redirect 301 /oldpage.html http://www.example.com/newpage.html

But I'm not sure how to do this when both the page location and the HTTP/HTTPS is changing as well as the www going away. The site ranks pretty well and I don't want to lose any of that.

I've researched but can't find an example of doing both at the same time.

Ad

Answer

You should be able to do using rule like this:

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^contact\.php$ https://%1/contact-us/ [R=301,L,NC]

Since your page names are different you will need multiple rules like this.

Make sure to keep these rules above all other rules.

Ad
source: stackoverflow.com
Ad