Www to non www
-
Hi,
Is this the correct code for redirecting www to non www version on Apache server
RewriteEngine
OnRewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Thanks
-
Many Thanks to all of you for your clarifications .
-
Double post... I only clicked one though so... random!
Also, yukky windows servers hehe
-
Hehe I was going non www to www wasn't I, I should learn to read properly, well spotted!
-
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Put that in your .htaccess within your root web directory (typically public_html), and you should be good.
Make sure you save your .htaccess file properly (save as "All files" and not "as text file" so the .txt doesn't get appended to it.
-
The $1 basically copies everything that precedes it ( http://www.example.com/ )
This is so that for each URL it rewrites you don't have to give it the above URL over and over again.
Hope this makes sense
**'**If the matched regex contains groups in parentheses, $1..$9 in the replacement refer to the captured text in the
matching group "$1" meaning the first group, "$2" the second, and so on.' -
Look i work on windows servers so i dont use htaccess, so i am no expert with htaccess, but I do know regex pretty well,
I think you have it wrong in 2 ways.
- you are directed from non www. to www the wrong way.
Also the rewrite condition is a RegEx, it needs to be escaped
so i think you should have
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
This is all so much easier on windows servers
-
Is this correct
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
What does $1 mean ?
-
You've just missed the "on" at the end of the first line and have it at the start of the 2nd I think (not sure if that matters). So,
RewriteEngine On
And then take the www off the second line. So,
RewriteCond %{HTTP_HOST} ^example.com
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
I have two robots.txt pages for www and non-www version. Will that be a problem?
There are two robots.txt pages. One for www version and another for non-www version though I have moved to the non-www version.
Technical SEO | | ramb0 -
Ranking for non-existing content which is 301 redirected
Hey there, In the beginning of this year I've made complete site migration from Dutch language to English. All the old Dutch URL's were 301 redirected to the English versions. I naturally lost rankings for all Dutch keywords during the next month. On the website there is no Dutch content anymore. But what happened now is that five months later the website started to rank for the Dutch keywords again. The page snippets in SERP are in English but the URL's shown are in Dutch (ending with .nl) and whenever a user clicks on the snippet he/she gets 301 to the correct English version. Any ideas what could be the reason for re-ranking of non-existing pages which gets 301 in SERP?
Technical SEO | | benesmartin0 -
Www to non-www redirect without loop still necessary?
Hi Guys, My question is: Is it still necessary to redirect www. to non www. version of your website or other way around?
Technical SEO | | gaben
I ask because I feel that Google should be able to read these as the same by now. Thank you in advance.
Gabe0 -
Is my website indexed correctly in Google - www.couponshop.co.uk
Our website www.couponshop.co.uk has just had a relaunch after a change of direction.
Technical SEO | | LaurenGT
A lot of the pages were redirected. When I checked the indexing of the website on Google, I put site:couponshop.co.uk and only two pages come up, but when I put site:www.couponshop.co.uk they all show up.
Is this correct or are we doing something wrong?0 -
Bad SEO is being done to www.myproactivechiro.com
Since January of 2013 my site's rankings have tanked, I don't know who, or old SEO firm that I left is doing this. A lot of bad links are coming from Russia and are killing my rankings, I need help what do I do, do I just start a new domain? thanks Alec
Technical SEO | | akhlebo0 -
Capitals URLs to Non Capitals...
Hi, I am working on a website which has capital urls and non capital urls which will be generating duplicate content, and I know it is better to use all lower case. The problem is that the page authority is better for the capital versions and I was wondering will it negatively impact the SEO of we 301 redirect the uppercase urls to the lowercase counterparts? Thanks.
Technical SEO | | J_Sinclair0 -
Hreflang on non-canonical pages
Hi! I've been trying to figure out what is the best way to solve this dilemma with duplicate content and multiple languages across domains. 1 product info page 2 same product but GREEN
Technical SEO | | LarsEriksson
3 same product but RED
4 same product but YELLOW **Question: ** Since pages 2,3,4 just varies slightly I use the canonical tag to indicate they are duplicates of page 1. Now I also want to indicate there are other language versions with the_ rel="alternate" hreflang="x" _element. Should I place the _rel="alternate" hreflang="x" _on the canonical page only pointing to the canonical page with "x" language. Should I place the _rel="alternate" hreflang="x" _on all pages pointing to the canonical page with the "x" language? Should I place the _rel="alternate" hreflang="x" _on all pages and then point it to the translated page (even if it is not a canonical page) ? /Lars0