Redirect mysite.com to www.mysite.com

For a site in linux hosting, where can I configure that if my website is intended to be accesed without the “www”, be redirected immediatly to the one with the “www” ?

you can create .htaccess file in root of your domain with following lines :

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]


Just replace domain.com to your actula domain name.

Most people I have seen that want to do this implement it in code as the most reliable way.

Or for linux do what Deepak said :slight_smile: Since replied at the same time, his example is more useful.

Thank you !!

I have another little question on this topic.

I’ve just moved my forum to www.mysite.com/foros/

I don’t want nothing on the root since I will install another CMS later that I want to be the root. So, this is where the forums will be since now on.

I tried to modify the .htaccess file to now redirect to this subdirectory, but I got something like www.mysite.com/foros/foros/foros/foros/foros/etc , etc.
How do I do this ?

I did this and seems to work :

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mysite.com [nc]
rewriterule ^(.)$ http://www.mysite.com/$1 [r=301,nc]
RewriteCond %{REQUEST_URI} !^/foros/
RewriteRule ^(.
)$ /foros/ [r=301,nc]

Yes, this is the correct way of creating redirection.
Previously you created a looping redirection .