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
-
SERP Review Features show on a non-product page?
When reviewing my campaign's SERP Features, I notice that one of my competitors is gaining a lot of Review Features that I'm missing. I'm ranking high for the keywords that are showing the review features, but not on my product page. I'm ranking for those keywords on blogs and other pages. Is there a way to show for those review features as I currently have it, or should I be trying to rank for those keywords on my product page? I appreciate any insight into this situation.
Technical SEO | | LearningStuff0 -
Penalized domain redirected to the non-penalized one...
I've a technical question , For example site A was penalized by google updates, panda and penguin both and site b is in the same niche and it's running good and never been penalized by updates. If I redirect site A to Site B with 301 status code(permanent redirect), will Google penalize the site B too? because penalties travel from old domain to new one as per google's algorithms. And If yes then how can I stop my competitor from removing redirection of penalized domain to mine?
Technical SEO | | hammadrafique0 -
Www2 vs www problem
Hi, I have a website that has an old version and a new version. The content is not duplicate on the different versions.
Technical SEO | | TihomirPetrov
The point is that the old version uses www. and non-www before the domain and the new one uses www2. My questions is: Is that a problem and what should be done? Thank you in advance!0 -
Redirect root domain to www
I've been having issues with my keyword rankings with MOZ and this is what David at M0Z asked me to do below. Does anyone have a solution to this? I'm not 100% sure what to do. Does it hurt ranking to have a domain at the root or not? Can I 301 redirect a whole site or do I have to do individual pages. "Your campaign is looking for rankings for the www version of the campaign but the URL resolves as a root domain. This would explain the discrepancy. Since there is no re-direct between the two, you can have brickmarkers.com 301 re-direct to www.site.com which will prevent you from re-creating your campaign to track the root domain. Once the re-direct is in place it will take a while for Google to show the www version in the results in which your campaign rankings will be accurate." Thanks
Technical SEO | | SeaDrive0 -
Www vs no-www duplicate fix?
Hi all, I have more or less published two versions of our site. One on "www" and one without. And of course we uncovered it during our SEO crawl as "duplicate" content/titles. My guess (hope) is this is something that can be easily fixed on the server side, but I don't have a lot of knowledge around it. Does anyone know?
Technical SEO | | Becky_Converge0 -
How do I stop www.mysite.com/ showing as a duplicate of www.mysite.com
I have run the campaigns software over a site and it is showing that www.mysite.com/ is a duplicate of www.mysite.com, how do I correct this? Is it a genuine duplicate page? My first thought was to use rel canonical but there is no page called / to put it on. Your suggestions welcomed Sean
Technical SEO | | ske110 -
Duplicate content issue. Delete index.html and replace with www.?
I have a duplicate content issue. On my site the home button goes to the index.html and not the www. If I change it to the www will it impact my SERPS? I don't think anyone links to the index.html.
Technical SEO | | bronxpad1 -
If non-paying customers only get a 2 min snippet of a video, can my video length in sitemap.xml be the full length?
I am working on a website that all of its primary contents are videos. They have an assortment of free videos, but the majority or viewable only with a subscription to the site. If you don't have a subscription, you can see a 2 min video clip of the contents of the video. But all the videos can be anywhere from 10min to 1.5 hours. When I am auto-generating the sitemap.xml, can I put the full length of the videos for paying members in the XML in the video:duration property? Or because publicly only 2 minutes is available (unless you pay for a membership) is that frowned upon?
Technical SEO | | nbyloff0