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
-
Best redirect destination for 18k highly-linked pages
Technical SEO question regarding redirects; I appreciate any insights on best way to handle. Situation: We're decommissioning several major content sections on a website, comprising ~18k webpages. This is a well established site (10+ years) and many of the pages within these sections have high-quality inbound links from .orgs and .edus. Challenge: We're trying to determine the best place to redirect these 18k pages. For user experience, we believe best option is the homepage, which has a statement about the changes to the site and links to the most important remaining sections of the site. It's also the most important page on site, so the bolster of 301 redirected links doesn't seem bad. However, someone on our team is concerned that that many new redirected pages and links going to our homepage will trigger a negative SEO flag for the homepage, and recommends instead that they all go to our custom 404 page (which also includes links to important remaining sections). What's the right approach here to preserve remaining SEO value of these soon-to-be-redirected pages without triggering Google penalties?
Technical SEO | | davidvogel0 -
Www to non www on a .com/blog url
hi guys, I have had to reset my site from www to non-www. via htacces and this worked out just fine.However, the /blog WordPress section will not redirect to the non-www. I have changed the config.php to non-www. However, the /blog WordPress section will not redirect to the non-www. I have changed the config.php to non-www. Does anyone have an idea as to what I need to do to force the non-www in a folder installed blog http://5starweddingdirectory.com/ http://www.5starweddingdirectory.com/blog/ Regards T
Technical SEO | | Taiger0 -
Remove a page after redirection
Hi, I had page eg. www.example.com/page1 and I redirect 302 it to > www.example.com/page2 After that I fatch this page (page2) with GSC and this page was index in serp. Can I remove this old redirect page > www.example.com/page1 now? Will this remove harm my page?
Technical SEO | | Tormar0 -
3,511 Pages Indexed and 3,331 Pages Blocked by Robots
Morning, So I checked our site's index status on WMT, and I'm being told that Google is indexing 3,511 pages and the robots are blocking 3,331. This seems slightly odd as we're only disallowing 24 pages on the robots.txt file. In light of this, I have the following queries: Do these figures mean that Google is indexing 3,511 pages and blocking 3,331 other pages? Or does it mean that it's blocking 3,331 pages of the 3,511 indexed? As there are only 24 URLs being disallowed on robots.text, why are 3,331 pages being blocked? Will these be variations of the URLs we've submitted? Currently, we don't have a sitemap. I know, I know, it's pretty unforgivable but the old one didn't really work and the developers are working on the new one. Once submitted, will this help? I think I know the answer to this, but is there any way to ascertain which pages are being blocked? Thanks in advance! Lewis
Technical SEO | | PeaSoupDigital0 -
Added 301 redirects, pages still earning duplicate content warning
We recently added a number of 301 redirects for duplicate content pages, but even with this addition they are still showing up as duplicate content. Am I missing something here? Or is this a duplicate content warning I should ignore?
Technical SEO | | cglife0 -
IP redirects
My website, on a .com domain, displays a different language/content depending on the IP of the user. For example, if someone is browsing my web from Spain, it will show the spanish content, and so on. Does anyone has an idea on how will Google index my pages? Their servers being located in the US, I assume the bot will only crawl and index the english content. How can I tell the bots to do the same for the other languages/content? Thanks!
Technical SEO | | Alemoto0 -
Page rank 2 for home page, 3 for service pages
Hey guys, I have noticed with one of our new sites, the home page is showing page rank two, whereas 2 of the internal service pages are showing as 3. I have checked with both open site explorer and yahoo back links and there are by far more links to the home page. All quality and relevant directory submissions and blog comments. The site is only 4 months old, I wonder if anyone can shed any light on the fact 2 of the lesser linked pages are showing higher PR? Thanks 🙂
Technical SEO | | Nextman0