I currently have this code: <VirtualHost *:80> ServerName domain.com UseCanonicalName Off RewriteEngine on RewriteCond %{HTTP_HOST} ^domain\.com RewriteRule ^(.*)$ http://www.domain.com$1 [R=permanent,L] LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon CustomLog logs/access_log vcommon VirtualDocumentRoot /home/%-3/public_html #VirtualScriptAlias /www/hosts/%-3/cgi-bin </VirtualHost> Code (markup): But there is a couple of problems with it, it redirects all urls to www. that do not have www at the start. But I do not want to it redirect sub domains only domain.com. So: domain.com would become www.domain.com www.domain.com wouldnt change test.domain.com wouldnt change etc What would I need to do to make this work? Thanks in Advance
Try changin this two lines: RewriteCond %{HTTP_HOST} ^domain\.com RewriteRule ^(.*)$ http://www.domain.com$1 [R=permanent,L] Code (markup): into this three lines: RewriteCond %{HTTP_HOST} ^domain\.com [NC,OR] RewriteCond %{HTTP_HOST} !^(.+\.)?domain\.com$ [NC] RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L] Code (markup): I haven't tested it, but I think it should work fine. Cheers!
It works fine but when using www.domain.com and domain.com it puts // at the end of the url. Why is it doing this ?
Well, you can specify a custom 404 page using the following line in your .htaccess ErrorDocument 404 /404.html Code (markup): Which will return 404 status code and open that specific 404.html page (or whatever you name it). However it will not redirect it to another link, or index page. You could specify something like: ErrorDocument 404 http://www.domain.com/ Code (markup): HOWEVER, although it will do what you wish and redirect each 404 error visitor to your index page, the server will NOT return actual 404 status, but either 200 or 302, which is not good for your SEO optimization probably. So i would suggest creating a custom error page. The same applies to 403, just replace 404 with 403 in that ErrorDocument line. Cheers.