I would like to modify my .htaccess file so that when someone comes into my site without typing www the site always redirects them to the www version. For example, if my ur
If you want redirect example.com to www.example.com you can try below code
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
There are two methods available
1) use mod_alias apache module
Redirect permanent /something http://yourwebsite.com/something
2) Add the following entry in your .htaccess / http.conf / yourwebsite.conf in the webserver configuarion directory
RewriteEngine on RewriteCond %{HTTP_HOST} ^yourwebsite.com RewriteRule ^(.*)$ http://www.yourwebsite.com$1 [R=permanent,L]
Add something like this immediately after RewriteEngine on
:
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
I use the code below. It can be used for any domain name. You just need to enter it in your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
(edited to have all the code in the same block)