Tech

HTACCESS 301 Redirect all URL Variations to the Live URL

Author By Chandan Kumar
December 7, 2017
8 min read
Share:
HTACCESS 301 Redirect all URL Variations to the Live URL

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 which will help you 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 URLs to https://www.xyz.com/sample-page/

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 reply to you in 24 hours. I will be glad to help others.

Chandan Kumar

Chandan Kumar

Related Articles

Continue reading with these hand-picked articles on similar topics.

Website Launch Checklist 2025: 20+ Ultimate Before and After Launch Tasks
Tech
Website Launch Checklist 2025: 20+ Ultimate Before and After Launch Tasks
Launching a website? Don’t miss a step! This all-in-one checklist covers everything from planning to promotion for a seamless, successful launch.
Chandan Kumar March 24, 2025
A Complete Guide to reCaptcha Accessibility Solution
Tech
A Complete Guide to reCaptcha Accessibility Solution
Recaptcha accessibility solutions come in various forms, including text-based CAPTCHAs, image-based CAPTCHAs, reCAPTCHAs, and mathematical CAPTCHAs.
Chandan Kumar July 7, 2022
Web Application Development Best Practices & Resources
Tech
Web Application Development Best Practices & Resources
Businesses today require custom web applications that provide an optimal user experience across devices, platforms, and browsers to increase their online presence.
Chandan Kumar June 21, 2021