How do I redirect non www pages to www on a windows server?
-
As the .htaccess file cannot be worked on, I added this php code 301 redirect if the URL does not contain a www on all the pages (small website - 10 pages) :
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: $location" );
I want to know if this is ok for SEO? Has anyone done this on a windows server? Or if you have any better methods, it would be great if you can share.
Please help.
Thanks.
-
If you want to go to the www version, then you want
"^www.oberoihotels.com$"
and
{R:1to url="http://www.oberoihotels.com/{R:1
look for this tag
you dont want to have 2, if you already have one add the code to that one.
let me know if you have anny problems
-
Hi Alan, They are not able to do it via the control panel - and there is no way that they will share the password for us to do it. Therefore I think we have to do it manually. Can you please check if this code is correct. I have replaced my domain.com.au to www.oberoihotels.com (as an example) in 2 places : Changed "^mydomian.com.au$" to "^oberoihotels.com$" and changed url="http://mydomain.com.au/{R:1to url="http://oberoihotels.com/{R:1 Is this correct? Therefore the new code to add to the web.config file :<system.webserver><rewrite><rules><rule name="CanonicalHostNameRule"><match url="(.*)"><conditions><add input="{HTTP_HOST}" pattern="^oberoihotels.com$" negate="true"></add></conditions><action type="Redirect" url="http://oberoihotels.com/{R:1}"></action></match></rule><rule name="LowerCaseRule" stopprocessing="true"><match url="[A-Z]" ignorecase="false"><action type="Redirect" url="{ToLower:{URL}}"><conditions><add input="{URL}" pattern="WebResource.axd" negate="true"><add input="{URL}" pattern="Scripts" negate="true"><add input="{URL}" pattern="Content" negate="true"></add></add></add></conditions></action></match></rule></rules></rewrite></system.webserver>
-
Yes the control panel will put the code in the web.config for you, or uyou can put it in manualy.
The code above has 2 riles in it, to fix domain name, the other to make sure url is lower case
-
Thanks Alan. It's very clear what to do now. I don't have access but will speak to the people who do have access and see if it can done the way you mentioned using URL redirect from the server control panel itself.
Thank you!
Arjun
-
go to yout iis server control panel look for url rewriting, if it is not there install it using web platform installer.
then it is a simple ass picking it from a list.
You can also do it in code, using a class inherting the httpmodule this intercepts request before reaching website.
But the easiest way is using the URL rewriting as i suggested.
If tyou dont have access. plonk this in your web.config, change from mydomain.com.au to your own domain
<system.webserver>
<rewrite><rules><rule name="CanonicalHostNameRule"><match url="(.*)"><conditions><add input="{HTTP_HOST}" pattern="^mydomian.com.au$" negate="true"></add></conditions>
<action type="Redirect" url="<a href=" http:="" mydomain.com.au="" {r:1"="">http://mydomain.com.au/{R:1}" />
</action></match></rule>
<rule name="LowerCaseRule" stopprocessing="true"><match url="[A-Z]" ignorecase="false"><action type="Redirect" url="{ToLower:{URL}}"><conditions><add input="{URL}" pattern="WebResource.axd" negate="true"><add input="{URL}" pattern="Scripts" negate="true"><add input="{URL}" pattern="Content" negate="true"></add></add></add></conditions></action></match></rule></rules></rewrite>
</system.webserver>
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
-
How effective are 301 redirects in passing page rank?
I have a blog which is ranking well for certain terms, and would like to repurpose it to better explain these terms it is ranking for, including updating the url to the new term the blog will be about. The plan being to 301 redirect the old url to new. In the past, I've done this with other pages, and have actually lost much of the rankings that I had earned on the original URL. What is your take on this? Maybe repurpose blog, but maintain original URL just to be on the safe side? Thanks
Technical SEO | | CitimarineMoz0 -
Non Published Wordpress Pages
Hi, Is there any negative SEO consequences from having too many pages private or not published. Can it like slow the site down or does it not matter? Someone in my dept. has so many pages started/not complete and besides being messy, I wonder if it has any negative impact on the site. Thanks
Technical SEO | | aua1 -
Thousands of 404-pages, duplicate content pages, temporary redirect
Hi, i take over the SEO of a quite large e-commerce-site. After checking crawl issues, there seems to be +3000 4xx client errors, +3000 duplicate content issues and +35000 temporary redirects. I'm quite desperate regarding these results. What would be the most effective way to handle that. It's a magento shop. I'm grateful for any kind of help! Thx,
Technical SEO | | posthumus
boris0 -
301 Redirect
Hello Moz Community, I have a question regarding 301 redirecting a new domain that contains keywords relevant to my website. However, I do NOT want to change my current domain. My main question is, by just redirecting this new domain to my current website, will those keywords in the new domain help with ranking in anyway? Thanks in advance for any help!
Technical SEO | | WyzeOwl0 -
Linux Server recognizing ASP Pages (301)
Greeting, I am in the process of 301 a group of pages on our site. We are thinking about switching from ASP to a Linux Server. Question 1. - Would anyone have any information of creating a Sever Spoof so that the Linux Server will recognize asp pages for a 301? Question 2 - How will this style of 301 Effect SEO rankings? Thanks, Tony
Technical SEO | | Tonyd230 -
Renaming of pages
About 2 months ago one of our clients renamed a section of his website. The worst part is that the URLs of the page also changed. New page: http://www.meresverige.dk/rejser/malmo Old page: http://www.meresverige.dk/rejser/malmoe The problem now is that the new page get absolutely no page-rank transfered from the old page. It also get no mozrank at all. Also if I try to find it in the Open Site Explorer it can not be found.The old page can, but not the new one. We have updated the sitemap.xml and also done proper 301 redirect for the pages since about 2 months. Any ideas here? This page was a very important page in terms of traffic so very much thankful for any input. Have a great day Fredrik
Technical SEO | | Resultify0 -
Indexed non www. content
Google has indexed a lot of old non www.mysite.com contnet my page at mysite.com still answers queries, should I 301 every url on it? Google has indexed about 200 pages all erogenous 404's, old directories and dynamic content at mysite.com www.mysite.com has 12 pages listed that are all current. Is this affecting my rankings?
Technical SEO | | adamzski0 -
Too many on page links for WP blog page
Hello, I have set my WP blog to a page so new posts go to that page making it the blog. On a SEOmoz campaign crawl, it says there are too many links on one page, so does this mean that as I am posting my blog posts to this page, the search engines are seeing the page as one page with links instead of the blog posts? I worry that if I continue to add more posts (which obviously I want to) the links will increase more and more, meaning that they will be discounted due to too many links. What can I do to rectify this? Many thanks in advance
Technical SEO | | mozUser14692366292850