Generic htaccess redirect www to non-www

0
0 Comments

I would like to redirect www.example.com to example.com. The following htaccess code makes this happen:

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

But, is there a way to do this in a generic fashion without hard coding the domain name?


Discover more from Muft Shiksha™ | मुफ्त शिक्षा

Subscribe to get the latest posts sent to your email.

Akbar Khan Answered question 5 Apr, 2024
0
RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Discover more from Muft Shiksha™ | मुफ्त शिक्षा

Subscribe to get the latest posts sent to your email.

Akbar Khan Answered question 5 Apr, 2024
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.
Join for Teach