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
-
Www to non www on a .com/blog url
hi guys, I have had to reset my site from www to non-www. via htacces and this worked out just fine.However, the /blog WordPress section will not redirect to the non-www. I have changed the config.php to non-www. However, the /blog WordPress section will not redirect to the non-www. I have changed the config.php to non-www. Does anyone have an idea as to what I need to do to force the non-www in a folder installed blog http://5starweddingdirectory.com/ http://www.5starweddingdirectory.com/blog/ Regards T
Technical SEO | | Taiger0 -
Redirect non slash to slash
Hello SEO gurus We have an issue here ( www.xyz.com.au) is having 200 responses www.xyz.com.au and www.xyz.com.au/ ( when i ran the crawl test i found this ) We have been advised to do a 301 from non slash to slash ( as our other pages are showing up with slash ) for the consistency we decided to go with this but our devs just couldnt do it. Error is - redirect loop and this site is a wordpress one Can anyone help us with this issue? Help is much appreciated.
Technical SEO | | Pack0 -
Redirecting non-www to www
Hi all, I recently ran my first diagnostic test with SEOmoz and was alarmed to find my company's site has over 8,000 cases of duplicate content, virtually all of which can be attributed to separate domains, www vs. non-www. So after some research I found that this can be solved easily using .htaccess. However I found a warning on another site that if my site has already been indexed by Google without the www, there could be side effects like a loss in PR. Can anybody tell me how to find out whether my site falls into this category? I do have access to Google Webmaster tools but I can't find anywhere that tells me how my site's been indexed. Thanks in advance.
Technical SEO | | rylaughlin0 -
Would removing or making non relevant links no follow boost a site?
Hi, I have just been checking out the backlinks for a prospective new client. It appears they have a number of links that are totally irrelevant to their nature of business and I was wondering if they would improve in the rankings etc if I removed them or made them no follow instead? Or would I simply just be throwing away crucial link juice? Thanks in advance
Technical SEO | | Benjamin3790 -
How best to deal with www.home.com and www.home.com/index.html
Firstly, this is for an .asp site - and all my usual ways of fixing this (e.g. via htaccess) don't seem to work. I'm working on a site which has www.home.com and www.home.com/index.html - both URL's resolve to the same page/content. If I simply drop a rel canonical into the page, will this solve my dupe content woes? The canonical tag would then appear in both www.home.com and www.home.com/index.html cases. If the above is Ok, which version should I be going with? - or - Thanks in advance folks,
Technical SEO | | Creatomatic
James @ Creatomatic0 -
Expired Domain - http:// or www
I have an old domain - When i use the link explorer i get way more juice out of the www version of my domain. I will be using wordpress to set up a new domain with the same name . My question is - How do I make it proper for seo? Do i just change the http:// to www in wordpress and be done with it? Does it even matter (thinking it does)
Technical SEO | | imagatto20 -
Redirecting blog.<mydomain>.com to www.<mydomain>.com\blog</mydomain></mydomain>
This is more of a technical question than pure SEO per se, but I am guessing that some folks here may have covered this and so I would appreciate any questions. I am moving from a WordPress.com-based blog (hosted on WordPress) to a WordPress installation on my own server (as suggested by folks in another thread here). As part of this I want to move from the format blog.<mydomain>.com to www.mydomain.com\blog. I have installed WordPress on my server and have imported posts from the hosted site to my own server. How should I manage the transition from first format to the second? I have a bunch of links on Facebook, etc that refer to URLs of the blog..com format so it's important that I redirect.</mydomain> I am running DotNetNuke/WordPress on my own IIS/ASP.Net servers. Thanks. Mark
Technical SEO | | MarkWill0 -
Www vs non-www
We just had our site redesigned. Previously, it was indexed under www.suss.net, but now the developer has it at suss.net with www.suss.net 301 redirecting to suss.net. Is this bad for SEO?
Technical SEO | | kylesuss0