Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic domain htaccess redirection

I created www domain redirection in htaccess file:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
ErrorDocument 404 /

All works, but I do not want enter manualy domain name every time. How to change example.com to dynamic domain name? Can somebody help me?

like image 693
Aleksandar Avatar asked Oct 27 '25 05:10

Aleksandar


1 Answers

You can use:

ErrorDocument 404 /
RewriteEngine On 

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
like image 121
anubhava Avatar answered Oct 29 '25 17:10

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!