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 do you fix redirect chains and temporary redirects?
Hi, I have a lot of issues popping up with temporary redirects and redirect chains. I'm still confused as to what exactly redirect chains are and I don't know how to find where the "chains" are or how to fix them. I'm having two issues mainly:1. Temporary RedirectsI have around 100 pages on our www.twowayradiosfor.com website that are being flagged as temporary redirects. All of them have one thing in common: they are review pages (basically, when a customer clicks on the Review button to review a certain product, they are redirected to a review page for that product).URL Example: https://www.twowayradiosfor.com/reviewhelpful.asp?ProductCode=CLS1410-COMBO&ID=44&yes=noI went into our website and set any URL containing the following as noindex:/review.aspWill that fix the issue? If yes, will I also need to do that for any URL containing /reviewhelpful.asp?2. Redirect ChainsIt seems like basically every product page on my website has this issue (over 100 pages). Here's an example of one:https://www.twowayradiosfor.com/Motorola-CLS1110-p/cls1110.htmI don't see any broken links on this page or links that redirect to another page that redirects, etc. What is causing this? Is it something on my header bar that is redirecting (since that header bar appears on every page, maybe that is why this issue shows up on a lot of pages)?I am new to Moz and still trying to figure this stuff out. I really appreciate any help. Thanks, Sawyer
Technical SEO | | AllChargedUp0 -
From page 1th to page 18th @ Google
Hello Mozzers! I have a question, you may help.. How may it be possible that a page ranking well (1th result) goes from 1th result to the 18th page just in 1 day? It doesnt seem to be any kind of penalization.. I now had all suspicious outgoing links to be nofollow (they were not before), this may be a cause .. (?) Do you have any other suggestion? Thanks
Technical SEO | | socialengaged0 -
Help! www and non-www urls are driving me mad!
Sorry folks, I'm a very recently joined member, and after a five year gap in creating websites, I've decided to get back into the saddle and start again. Boy how things have changed! I'm soaking up all sorts of information from everywhere I can to get up to date with these changes, but I've come across this www v non-www problem in a big way. I realise there are already posts in here about this, but each time I read them, my mind seems to slip into some sort of loop that does not get anywhere. Basically, I think Google has indexed most of my pages as non-www, and only a hadful as www's. I have opened two accounts in Google Webmaster Tools for both www and non-www, and declared my preference for both accordingly. That was two days ago. As unprofessional as it may sound, I use Serif Web Plus X6, simply beacause it did the job six years ago, and it's all I know until I find and teach myself something better. My question is this - I can only create one page on X6, and yet there are two versions indexed in Google (although not all of them). I can only amend the one page that exists in X6, so how do I canonicalize two pages when there's the only version I have access to amending? Or am I miissing the point??? I hope that made sense?! I wouldn't mind, but I specified that I didn't want the site to be indexed yet with 'no follow', as it's nowhere near finished, but for some reason (probably due to placing Adsense ads on there) Google went ahead and indexed it anyway! The site is either http://www.cushioncutengagementringsstore.com or http://cushioncutengagementringsstore.com, depending on how you look at it! Any light you can shed on this would be gratefuly received! Thanks. Cem.
Technical SEO | | ConwyWebDesign0 -
Setting preferred domain as www or none www
Way back before panda I used to rank for certain keywords pretty well. Of course like many others after panda I lost some of those rankings. I have been getting better since then so its not that bad. I was poking around in Google Webmaster Tools and I noticed something which I need some clarification in. History my site freescrabbledictionary.com used to be indexed as a none www. Then some time ago I can't remember when I set it to www. Tonight I was looking through my webmaster tools and I noticed something that did not make sense to me. In my content keywords section for the none www my list is as follows Content Keywords <form action="https://www.google.com/webmasters/tools/keywords-list?hl=en&siteUrl=http://freescrabbledictionary.com/" method="GET"> Keyword Significance 1. scrabble 2. words (2 variants) 3. dictionary 4. cheat 5. finder 6. friends 7. maker (2 variants) 8. noun 9. letter (2 variants) 10. hasbro 11. mattel 12. spear 13. found (2 variants) 14. sowpods 15. freescrabbledictionary 16. builder 17. affiliated 18. search 19. solver 20. lists </form> Then I looked at my www lists and its Content Keywords <form action="https://www.google.com/webmasters/tools/keywords-list?hl=en&siteUrl=http://www.freescrabbledictionary.com/" method="GET"> Keyword Significance 1. words (3 variants) 2. scrabble (2 variants) 3. letter (4 variants) 4. points 5. cheat (3 variants) 6. friends (2 variants) 7. finder (2 variants) 8. anagram (2 variants) 9. dictionary 10. tool (2 variants) 11. hasbro 12. mattel 13. spear 14. game (4 variants) 15. mobile 16. affiliated (3 variants) 17. berkshire 18. canada 19. calculations (5 variants) 20. coming (4 variants) </form> My none www version has the order (especially the first 5 keywords) that I want, my www version is no were near it. If I change back to the none www version could I possible see an change in rank? or can it effect it if I change it? I am starting to think I shot myself in the foot when I switched...
Technical SEO | | cbielich0 -
My home page 301 redirects - is this an SEO problem
When ever a browser calls my site canineconcepts.co.uk, it is automatically 301 redirected to canineconcepts.co.uk/en I am not sure if I should be concerned about this from an SEO perspective or not. Any thoughts?
Technical SEO | | CanineConcepts0 -
Can I redirect when Google is showing these as 2 different pages?
Hi Guys, Google webmaster is showing 1000 duplicate title tags because its picking up our pages like this. How can I correct this? Please explain in detail please. Thank You Tim /store/ICICLES_NO_7_CLEAR_WITH_PINK_NUBBY//store/ICICLES_NO_7_CLEAR_WITH_PINK_NUBBY
Technical SEO | | fasctimseo0 -
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