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???

  • Do a simple search and replace? Search for http://www.mydomain.com replace with http://mydomain.com. Sorry maybe I'm missing something? – joesk Feb 12 '13 at 21:35
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]
  • 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???? – thetripdaddy Feb 12 '13 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 Feb 12 '13 at 23:56
  • If you don't start with the slash http://www.example.com/ gets redirected to http://example.com// – Stephen Ostermiller Feb 13 '13 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 Feb 13 '13 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 – Stephen Ostermiller Feb 13 '13 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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