What is the code to 301 http to www in htaccess file on unix server
-
i want to 301 my http home page to www on a linux server and all my other redirects are set up similar to this in my htaccess file:
redirect 301 /example-page.html http://www.example-page.html
how do I 301 redirect:
http://example.com to http://www.example.com
I've tried all kinds of code recommended for an htaccess file on a linux server and nothing seems to work.
Thanks for the help mozzers!
Ron
-
1st works fine for me....
Redirect 301 /tags/xp/ http://www.test.com/tags/windows-xp/
if it is not working there must be some other problem!
-
Hi Ron,
You will need to use URL rewrite and the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]That will redirect any page/file on example.com/file to www.example.com/file with a 301 redirect.
Hope that helps!
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
-
302 redirects, canonicalise or redirect (301)?
Hey Guys, I am fairly new to 'technical' SEO as I was lucky enough in my old role to have technical expertise in the team for things like this, now I am learning myself and it is a slow and painful process, so your expertise is soooo much appreciated! My I.T. dept say that I have 3 instances on my website where the Hybris platform is creating a 302 redirect automatically - the first: URL doesn't exist - Hybris creates a temp 302 - the system does not create case sensitive url's | http://www.example.fr/Example/Marques/0180/brand/CHANEL | URL doesn't exist | TRUE | 302 | | http://www.example.fr/Example/Marques/0015/brand/Giorgio-Armani | URL doesn't exist | TRUE | 302 |
Web Design | | eLab_London
| http://www.example.fr/fr/Example/marken/0507/brand/lancome | URL doesn't exist | TRUE | 302 | I believe these are being redirected due to the fact that capital letters are being created in the url. Multi-lingual redirects I have a German and French version of my site and whenever any switches from one URL to the other using our language selector a 302 is created. Dynamic URL elements Dynamic url elements and special characters are being created in the URL, I am not sure where this is happening, but my I.T. department would like me to go and see whether this is something that can be created by a browser. If anyone has any similar problems or have any advice or insights even, I would love to hear from you! Thanks 🙂0 -
Help with error: Not Found The requested URL /java/backlinker.php was not found on this server.
Hi all, We got this error for almost a month now. Until now we were outsourcing the webdesign and optimization, and now we are doing it in house, and the previous company did not gave us all the information we should know. And we've been trying to find this error and fix it with no result. Have you encounter this issue before? Did anyone found or knows a solution? Also would this affect our website in terms of SEO and in general. Would be very grateful to hear from you. Many thanks. Here is what appears on the bottom of the site( www.manvanlondon.co.uk) Not Found The requested URL /java/backlinker.php was not found on this server. <address>Apache/2.4.7 (Ubuntu) Server at 01adserver.com Port 80</address> <address> </address> <address> </address>
Web Design | | monicapopa0 -
Does using role="heading" instead of H1 in HTML code affects SEO?
Does using role="heading" instead of affect SEO? http://www.w3.org/WAI/GL/wiki/Headings_using_role%3Dheading
Web Design | | LNEseo0 -
Web development - License CSS/Markup/Code
In development of a website, is it typical for the developer to retain rights to the CSS, Markup and other Coding? If so, why is this done?
Web Design | | DemiGR0 -
Is it possible to redirect the main www. domain - but keep a subdomain active?
Hi Mozzers, Quick question, which I hope one of you can answer... Let's say I have a website (i) www.example.com and on that a subdomain exists, (ii) subdomain.example.com. Let's say I want to change my main domain from www.example.com to www.newwebsite.com. I'd 301 all content, use GWT to notify Google of a change of address etc etc. Having done that, is it still possible to keep the original subdomain active? So, even though www.example.com has been redirected / transferred to www.newwebsite.com, subdomain.example.com would still exist. If that is possible, what is the implication for Domain Authority? On the one hand, I have transferred the main site (so DA from that will transfer to the new site); but part of that root domain is still active. Make sense? Any answers? Thanks everyone...
Web Design | | edlondon0 -
SEO and Server Connectivity....
Good Morning/Evening Mozzers, I arrive at work this morning with 5 emails from GWT for my separate domains reading, **"Googlebot can't access your site - **Over the last 24 hours, Googlebot encountered 39 errors while attempting to connect to your site. Your site's overall connection failure rate is 15.1%." I have passed this on to the Web Dev team to resolve ASAP. My Question, will server connectivity issues harm my rankings? Is there a danger if this continues that URL's could be de-indexed? Input would be greatly appreciated.
Web Design | | RobertChapman0 -
Do you think it will be a good idea to delete old blog pages off the server
I paid somebody to build my website using Dreamweaver, and at one point I didn't know how to use the template which automatically updates every page in the menu section so I stupidly broke the template on every new page when I made the websites blog and put the pages into a subfolder. I realised this was a silly thing to do and now and I now know how to use the template correctly I've copied every single page over from the subfolder and put it into the main template. Now I can update the template menu and every page changes automatically. The only problem is I've now got two versions of every page of my blog on the website. For some reason when I do a sitemap it comes up with a links to the old blog pages I, don't know why when I've removed the links from the blog page? and also the new copies also. I have basically got a copys of all blog pages. Do you think it will be a good idea to delete old indexed blog pages off the server so that when Google spiders the site it will pick up only the new links to the copy pages?
Web Design | | whitbycottages0 -
Dynamic pages and code within content
Hi all, I'm considering creating a dynamic table on my site that highlights rows / columns and cells depending on buttons that users can click. Each cell in the table links to a separate page that is created dynamically pulling information from a database. Now I'm aware of the google guidelines: "If you decide to use dynamic pages (i.e., the URL contains a "?" character), be aware that not every search engine spider crawls dynamic pages as well as static pages. It helps to keep the parameters short and the number of them few." So we wondered whether we could put the dynamic pages in our sitemap so that google could index them - the pages can be seen with javascript off which is how the pages are manipulated to make them dynamic. Could anyone give us a overview of the dangers here? I also wondered if you still need to separate content from code on a page? My developer still seems very keen to use inline CSS and javascript! Thanks a bundle.
Web Design | | tgraham0