Hi, I've just added the following to my htaccess file to redirect www. visitors to the non-www. version of my site: RewriteCond %{HTTP_HOST} !^site\.com$ [NC] RewriteRule .* http://site.com/ [L,R=301] What I was wondering was if someone linked to my site with the www. would the link still count towards the non-www. version when using the redirect. The reason I ask is because people would naturally link to www. but I would still want this to have some effect rather than not counting as a backlink. Thanks for any help.
Yes, a 301 redirect is 'search engine friendly'. Also, regarding your rewriterules, you may want to redirect to the requested page rather than the homepage - if a user remembers the location of somewhere on your site and types in www.example.com/forums, they would prefer to be redirected to example.com/forums rather than just example.com RewriteCond %{HTTP_HOST} !^site\.com$ [NC] RewriteRule (.*) http://site.com/$1 [L,R=301] Code (markup): We simply capture the match in a backreference by putting it in parentheses. Then in the substitution, we call the backreference by $N (in this case N=1).
Thank you Richie and Rodney, that's good to know. I was also going to ask the exact question you've answered for me Rodney (but it slipped my mind!), regarding inner page redirects, so thanks for adding that.
That's good to know, but if you wanted to redirect to the www version of the requested page instead (other way around) how would you do this?
RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule (.*) http://www.site.com/$1 [L,R=301] Code (markup): should do it.
RewriteEngine On RewriteCond %{HTTP_HOST} !^(.*)\.domain\.com$ [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] Code (markup): Try this.
What pages are you trying to redirect (example url)? Do you have any other rewrite rules already in place?
Say for example... http://domain.com/page.php to http://www.domain.com/page.php The rewrite rules above seem to be just redirecting http://domain.com/page.php to http://www.domain.com/index.php
Is everything set up for rewriting? You could try the following two attempts but I wouldn't get your hopes up. The two rewrite rules already posted should work and I don't see why they're not. Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301] Code (markup): If still not, then another way of writing it would be: Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule (.*) http://www.site.com/%{REQUEST_URI} [L,R=301] Code (markup):