Menu Close menu

Welcome to AvyaTech Blog!

Home Tech HTACCESS 301 Redirect for all URL Variations to the Live URL

HTACCESS 301 Redirect for all URL Variations to the Live URL

htaccess 301 redirect for all urls

today I am writing about redirection errors for all variations of the website. This is a post about HTACCESS 301 Redirect for all URL Variations to the Live URL. I hope you people find this post helpful and share your suggestion below in the comment box.

Let’s check my example that will help you out to find the best answer.

Let’s say I want all the following URL variations to redirect to the live URL with a 301 status.

http://xyz.com/sample-page/
http://www.xyz.com/sample-page/
https://xyz.com/sample-page/

I want to redirect all these url to https://www.xyz.com/sample-page/

HTACCESS 301 Redirect for all URL Variations

Here is the solution to fix the problem easily,

  
RewriteCond %{HTTPS} off

RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I hope you people find this post helpful and don’t forget to share your feedback and question below in the comment box. If you need any help regarding this post or any other query just send me a mail and I will definitely reply to you back in 24 hours. I will be glad to help others.

Author: admin

Tags: , , ,

2 responses to “HTACCESS 301 Redirect for all URL Variations to the Live URL

  1. Atul Host December 10, 2017 at 4:54 pm

    Awesome, I was always confused with htaccess rules and this snippet of code is helpful.

    1. Chandan Kumar December 11, 2017 at 3:56 pm

      Thank you Atul, Good to know that you found it helpful.

Leave a Reply

Your email address will not be published.