skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. You can use the following :

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^www. [OR]
    RewriteCond %{HTTPS} off
    RewriteRule ^contact.php$ https://example.com/contact-us [NC,L,R=301,NE]
    

    The rule above rewrites the following requests :

    or

    to

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search