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
-
Does Designing in Sigma Reduce Coding Costs
A design service is using Figma to create modified form. Once the design is complete, Sigma will export CSS files. If we provide these CSS files to a coder, will this greatly reduce the required time to implement the. design on our website? Our website is designed. with a modified real estate theme. We are using exactly the same fields and functionality of the previous form. We are seeking to reduce coding time and subsequent costs. Thanks,
Web Design | | Kingalan1
Alan0 -
Site redesign - 301 Redirects
I've just overhauled a website, leaving lots of former posts in the dust. I've set up a 404 redirect to the home page so that if anyone goes to one of those old pages they land on the home page instead of a dead 404. But, there's a couple urls from the old site I'd prefer to redirect to similar pages. These urls have forward slashes and I don't know how to get the slashes in when I copy it over to the new site. This is probably something easy, but I'm baffled. This www.lawbarron.com/personal-injury/whip-its-nitrous-oxide/ becomes this when I copy it www.lawbarron.com/personal-injury-whip-its-nitrous-oxide Can someone help me out?
Web Design | | julie-getonthemap0 -
Website Server Issue?
I'm getting error messages that a website cannot be crawled and it might be due to the following issues: Couldn't access the webpage because the server either timed out or refused/closed the connection before our crawler could receive a response. How to fix: Please contact your web hosting technical support team and ask them to fix the issue Could Possibly Be:
Web Design | | PrimeMediaConsulting
1. DDoS protection system.
OR
2. Overloaded or misconfigured server They asked me to talk to my hosting company about this issue and he's at a loss (I don't think he knows everything he needs to know potentially). Have you seen these issues before? Where is the best spot to start troubleshooting this issue?0 -
How long should an old site redirecting to a new site remain activated on a server?
Once I switch a site to a new domain (with links to corresponding/relative pages), will I have to keep the old site live forever for those links to work, or how long should I wait before I inactivate the old site on our server?
Web Design | | jwanner0 -
.htaccess on wordpress multisites
Hi Moz fans, I have a site thats uses wordpress multisite. we have a number of sites set as subfolders i.e /en/ /de/ /us/ /fr/ ect. I need to force trailing slashes on each site as I currently have the pages being spidered as /about/ and /about and /iso-9001/ and /iso-9001. I have tried numerous things I have found online in the .htaccess and nothing is working. Can anyone HELP!!
Web Design | | imsmlouis0 -
Facebook code being duplicated? (Any developers mind taking a peek?)
I'm using a few different plug ins to give me various Facebook functions on my site. I'm curious there are any developers out there would could take a look at my source code and see if it looks there is some code being duplicated that's slowing down my site. Thanks so much!
Web Design | | NoahsDad0 -
Is it more beneficial to have internal links without the full file path?
When linking internally in my site is it more beneficial to have links written like, Fast Blenders OR Fast Blenders
Web Design | | tickettoss0 -
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