Hello, I have a website redirecting from www to non-www. I'm using the following .httaccess: RewriteEngine On RewriteCond %{HTTP_HOST} !^example\.com$ RewriteRule (.*) http://example.com/$1 [R=301,L] Code (markup): I also learned that my host has the option build in the control panel and i also set it up to redirect to non-www version of my website. My question is my .httacess code correct? and do i have to do anything else to not interfere with the cpanel assuming apache setting? i'm afraid that something could be wrong and upseting search engines. Thank you Kindly
I'm not sure its working. If you are using FF install "Live HTTP Header" You can easily track the header information Use like below RewriteEngine on RewriteCond %{HTTP_HOST} ^www.domain.com$ RewriteRule ^(.*) http://domain.com/$1 [L,R=301] Code (markup):
Thank you. while looking online I found the followng example: RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.exampleforum\.com$ RewriteRule ^(.*)$ http://exampleforum.com/$1 [L,R=301] Code (markup): I was wondering which one is better the first or the second, the only difference is the "^www\." Thank you
Performance-wise the difference is negligible. Technically the one that doesn't explicitly include www could match other subdomains, but since sub-domains are typically served from sub-directories that probably wouldn't matter for you, unless you have sub-domains that are served from the same DocumentRoot and just go to different files or something. Basically, if you have multiple domains reading the same htaccess it could be a problem. Other than that, I say just use whichever one you can look at and immediately remember what it means. Some people have trouble remembering that an exclamation mark means NOT, others may forget what the rule is for without the WWW in there somewhere.
Thank you Joe - I had somebody else suggesting the following code: RewriteCond %{HTTP_HOST} !^domain\.com RewriteRule (.*) http://domain.com/$1 [L,R=301] Code (markup): Now i'm confused, I just want to know which one to add Thank you
here's one tried and tested - works fine for server and with the search engines, Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^example\.com RewriteRule (.*) http://example.com/$1 [R=301,L] Code (markup): just replace example with your site name. ROOFIS