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
-
Is there a way to index important pages manually or to make sure a certain page will get indexed in a short period of time??
Hi There! The problem I'm having is that certain pages are waiting already three months to be indexed. They even have several backlinks. Is it normal to have to wait more than three months before these pages get an indexation? Is there anything i can do to make sure these page will get an indexation soon? Greetings Bob
Technical SEO | | rijwielcashencarry0400 -
Can Google show the hReview-Aggregate microformat in the SERPs on a product page if the reviews themselves are on a separate page?
Hi, We recently changed our eCommerce site structure a bit and separated our product reviews onto a a different page. There were a couple of reasons we did this : We used pagination on the product page which meant we got duplicate content warnings. We didn't want to show all the reviews on the product page because this was bad for UX (and diluted our keywords). We thought having a single page was better than paginated content, or at least safer for indexing. We found that Googlebot quite often got stuck in loops and we didn't want to bury the reviews way down in the site structure. We wanted to reduce our bounce rate a little, so having a different reviews page could help with this. In the process of doing this we tidied up our microformats a bit too. The product page used to have to three main microformats; hProduct hReview-Aggregate hReview The product page now only has hProduct and hReview-Aggregate (which is now nested inside the hProduct). This means the reviews page has hReview-Aggregate and hReviews for each review itself. We've taken care to make sure that we're specifying that it's a product review and the URL of that product. However, we've noticed over the past few weeks that Google has stopped feeding the reviews into the SERPs for product pages, and is instead only feeding them in for the reviews pages. Is there any way to separate the reviews out and get Google to use the Microformats for both pages? Would using microdata be a better way to implement this? Thanks,
Technical SEO | | OptiBacUK
James0 -
302 redirect and NO DATA as HTTP Status in Top Pages in SEOMOZ Link Analysis
I recently performed a link analysis using SEOMOZ and my home page (top page) indicates that there is a 302 status. Is this bad? Also, 2 other key landing pages have [NO STATUS] as the http status and [NO DATA] for the page title. Could anyone offer insight into what might be happening here, and whether or not it's something that is potentially hurting us? Thanks for your help!
Technical SEO | | dstepchew0 -
Www & non-www URL Issue
Hi is there any tools out there which can enable me to find pages which both serve www and non-www versions of each URL
Technical SEO | | monster990 -
Why are pages linked with URL parameters showing up as separate pages with duplicate content?
Only one page exists . . . Yet I link to the page with different URL parameters for tracking purposes and for some reason it is showing up as a separate page with duplicate content . . . Help? rpcIZ.png
Technical SEO | | BlueLinkERP0