3

I submitted a duplicate sitemap some time back to incorporate the www. addresses when I saw my site was not directing there when I typed it directly in the address bar. As I have edited my site and become better understanding of SEO I have done many 301 redirects for replaced pages, individually. No problem. Now I want to redirect the entire www. sitemap to my http sitemap. Must I redirect the entire mass of 4000+ urls individually or am I able to write a site level redirect... ie. site map directed to sitemap. The maps are identical except for the www. addition in the later one. The www. map has 105 listed urls while the http has 543. Any suggestions or knowledge concerning my best move???

1
  • Do a simple search and replace? Search for http://www.mydomain.com replace with http://mydomain.com. Sorry maybe I'm missing something?
    – joesk
    Commented Feb 12, 2013 at 21:35

1 Answer 1

4

You can use a single rule to redirect the entire site. Both of the following methods will redirect the following urls properly

http://www.example.com/ -> http://example.com/
http://www.example.com/page.html -> http://example.com/page.html
http://www.example.com/directory/page.html -> http://example.com/directory/page.html

If you have access to your httpd.conf file, you can redirect the entire site using a virtual host directive. This is better for performance that using .htaccess and rewrite rules.

<VirtualHost *>
    ServerName www.example.com
    Redirect 301 / http://example.com/
</VirtualHost>

If both your www and non-www hosts are served out of the same directory (and your host doesn't give you access to http.conf), you will need to use the following rewrite rules in your .htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
5
  • I am going to enter this code:...RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^/(.*)$ http://%1/$1 [R=301,L] .... is it just like this or must I add some pertinent information anywhere???? Commented Feb 12, 2013 at 23:26
  • 1
    Inside a per-directory .htaccess the RewriteRule pattern never starts with a / (slash) - yet thetripdaddy reports that this is working OK?
    – MrWhite
    Commented Feb 12, 2013 at 23:56
  • If you don't start with the slash http://www.example.com/ gets redirected to http://example.com// Commented Feb 13, 2013 at 0:09
  • Errm, no it doesn't?! Not in a per-directory .htaccess context (which I assume is what's being discussed here). However, the slash is required in a VirtualHost context. If I try this in a .htaccess file it simply doesn't work. This is as per the docs, "a Pattern with ^/ never matches in per-directory context."
    – MrWhite
    Commented Feb 13, 2013 at 0:53
  • I got that particular rule from stackoverflow.com/questions/234723/… and there were several comments about whether there should be a slash. Its not clear about which context people were trying to use it in. Based on your comment, I am editing the answer to remove the slash Commented Feb 13, 2013 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.