• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Automatically add www to naked domain

Y

yoannb

Guest
I would like to a domain automatically redirected to www when entering it in without a prefix in the browser.
How can i do this?

Thank You
 
Hi,

There is no connection with Plesk here, you can obtain this result with a simple .htacces file and appropriated rewrite rules. Google is your friend, you'll find answer quickly ;)
 
not exactly my solution, but thx

The .htaccess file is rewritten automatically by my ecommerce solution.
It works fine, the problem occurs when i go directly to a sub-directory.
I tried putting the htaccess file there but it doesn't work.
that's why I was hoping for a dns related solution...
 
this is something i had a problem with so i came up with a mod_rewrite rule list for htaccess that i just set as my vhost template.

Options +FollowSymLinks

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^.*/index.htm
RewriteRule ^(.*)index.htm$ http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^.*/home.htm
RewriteRule ^(.*)home.htm$ http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^.*/home.html
RewriteRule ^(.*)home.html$ http://%{HTTP_HOST}/$1 [R=301,L]

not only does it force the www domain, it strips out visitors ability to go to /index.html/htm or home.html/htm and instead directs them to /, cleans up analytics and server logs a lot and removes potential duplicate content from the search engines.
 
Back
Top