devofash
devofash

Reputation: 328

Redirect multiple domains to folder + non-www to www

So I'm using multiple domains and redirecting them to individual folders on my server.

I'm using .htaccess to do the redirect. I've managed to do the redirects but am to redirect non-www to www. So if somone typed in domain.com or domain.co.uk I'd like them to redirect to www.domain.com or www.domain.co.uk. Would appreciate some assistance please. Here's the code

# pointing for the domain domain.com or domain.co.uk to folder domain
ReWriteCond %{HTTP_HOST} ^domain.com [OR]
ReWriteCond %{HTTP_HOST} ^domain.co.uk [OR]
ReWriteCond %{REQUEST_URI} !domain/
ReWriteRule ^(.*)$ domain/$1 [L]  

Upvotes: 0

Views: 109

Answers (1)

Amine Hajyoussef
Amine Hajyoussef

Reputation: 4430

# redirect non-www to www
ReWriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301]

ReWriteCond %{HTTP_HOST} ^www.domain.com [OR]
ReWriteCond %{HTTP_HOST} ^www.domain.co.uk [OR]
ReWriteCond %{REQUEST_URI} !domain/
ReWriteRule ^(.*)$ domain/$1 [L]  

Upvotes: 3

Related Questions