0

There are many questions and answers on this topic. But I'm still stuck!

I've my basic .htaccess in my site that's working great and redirecting everyone my new site's home page.

Options +FollowSymLinks 
RewriteEngine on 

RewriteCond %{HTTP_HOST} ^oldsite.com [OR] 
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]

RewriteRule (.*) https://newsite.com [R=301,L]

But now, I'm trying to 'smartly' redirect users based on the following conditions:

IF {Page URL matches /services(.*)}
  THEN {Redirect users to http://newsite.com/solutions/}
ELSEIF {Page URL == /faq/faq1}
  THEN {Redirect users to https://newsite.com/faq/}
ELSE {Redirect users to https://newsite.com/} (root domain)

How to do it?

  • 1
    RewriteRule statements are evaluated in order, so just add the rules in order and place the catch-all redirect at end (which will be used if no earlier rule was matched). See the documentation for details. – sebasth Sep 20 '17 at 18:13
  • Thank you. But unfortunately all the page-to-page redirect rules are getting ignored and only the catch-all redirect is getting executed which is forcing the users to the home page only. Not sure what's wrong! – Ramnath Sep 21 '17 at 9:46
1

I assume you want to redirect to HTTPS in all cases and the http:// is just a typo.

RewriteCond %{HTTP_HOST} ^oldsite.com [OR] 
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^/services https://newsite.com/solutions/ [R=301,L]

RewriteCond %{HTTP_HOST} ^oldsite.com [OR] 
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^/faq/faq1 https://newsite.com/faq/ [R=301,L]

RewriteCond %{HTTP_HOST} ^oldsite.com [OR] 
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule .* https://newsite.com/ [R=301,L]
  • Thank you. But unfortunately all the page-to-page redirect rules are getting ignored and only the catch-all redirect is getting executed which is forcing the users to the home page only. Not sure what's wrong! I've even tried deleting the catch all condition. Then too, I'm landing in the home page. Hosting company says they do not provide coding help! Anything to do with https? – Ramnath Sep 21 '17 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.