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
-
301 Domain Redirect And Old Domain to a New one including pages
Hi, I need to 301 an old domain to a new one (new website) I need to 301 the domain to a new page not the new domain direct for example www.olddomain.co.uk to www.newdomain.co.uk/pagenew Then I need to also 301 all the other pages on the old domain to the new one for example... www.oldmain.co.uk/oldpage to www.newdomain.co.uk/newpage Issue is I can do one or the other not both, I can get the other pages to redirect but then the main domain wont redirect to the correct new page. Or I can get the old domain to redirect but not the internal pages. Thanks
Technical SEO | | David-Sharpe0 -
Page for page 301 redirects from old server to new server
Hi guys:
Technical SEO | | cindyt-17038
I have a client who is moving their entire ecommerce site from one hosting platform (Yahoo Store) to another (BigCommerce) and from one domain to another. The old domain is registered with the Yahoo as of yesterday and we have redirected the old domain (at the domain level) to the new domain. However, we are having trouble getting the pages to redirect page for page. Currently they are all redirecting to the new domain home page. We did just move the old domain from GoDaddy to Yahoo yesterday thinking this would solve it however as of this morning the old pages are still redirecting to the home page of the new domain. To complete the 301 redirect picture, we uploaded the redirects (all relative links for both from and to) to BigCommerce. And while the domain was hosted at GoDaddy with a redirect to the new domain, they were working. We moved the domain to Yahoo because of email issues thinking it should still work. Is it possibly just a waiting game now as the change populates across the DNS? old url to test:
rock-n-roll-action-figures.com/fender-jazz-bass-miniature-guitar-replica-classic-red-finish.html0 -
Updating inbound links vs. 301 redirecting the page they link to
Hi everyone, I'm preparing myself for a website redesign and finding conflicting information about inbound links and 301 redirects. If I have a URL (we'll say website.com/website) that is linked to by outside sources, should I get those outside sources to update their links when I change the URL to website.com/webpage? Or is it just as effective from a link juice perspective to simply 301 redirect the old page to the new page? Are there any other implications to this choice that I may want to consider? Thanks!
Technical SEO | | Liggins0 -
How do I resolve Twin domains? redirect website.com to www.website.com?
I am new to this website. Tried to run a campain and got a warning that website.com resolves to www.website.com which hinders SERP by competing for Keyword indexing!. (website is my domain name) Would appreciate help with this. Thanks. S.H. PS: here is the exact wording of error : We have detected that the domain www.yfvaccine.com and the domain yfvaccine.com both respond to web requests and do not redirect. Having two "twin" domains that both resolve forces them to battle for SERP positions, making your SEO efforts less effective. We suggest redirecting one, then entering the other here.
Technical SEO | | sherohass0 -
Redirect
Hello, I need to redirect just the homepage of my blog somewhere. So blog.com But there are other redirects in there and I don't want to override them. So blog.com/post.html How do I just redirect the homepage of wordpress page without redirecting all the other pages. This is what I did that recreated the issue. redirect 301 / blog2.com Thanks! Tyler
Technical SEO | | tylerfraser0 -
301 Redirect
Need a little bit of help on this one. I have a product page which actually has 3 products on the page in question: www.example.com/products I thought it would be best for each product to have a page on its own: www.example.com/product-1 www.example.com/product-2 www.example.com/product-3 however my question is: The page with the 3 products www.example.com/products where should the 301 go to? Can you do a 301 to all the new product pages? Hope that makes sense Kind Regards,
Technical SEO | | Paul780 -
Site:www.tld.com rank is it a measure of googles per page importance?
Hello, does the order of pages in a site:www.tld.com search show how important each page is to google? what if the homepage is not the first result?
Technical SEO | | adamzski0 -
Is my non-www domain working
I believe we may have an issue with out domains and links which is causing our seo to suffer. As far as I'm aware, our non-www domain is being treated as a different domain name. Open Site explorer returns different information for each one. However, when I go to the non-www domain in my browser (I have to force it using the http as otherwise the browser auto inserts the www) my browser returns a page cannot be found. But there may be a chance this is actually an issue with the server we access the internet via at work. I need to establish 100% beyond all doubt that our non-www domain is not working. This is the www: http://www.jetbookingdirect.com/ This is the non-www: http://jetbookingdirect.com/ If it is definitely not working, is the right thing to do to ask my web host to setup a 301 redirect? Further, I thought redirects could only point to one address. If we 301 redirect, if someone accesses a specific page via the non-www domain, does it then take them to the correct page? Also, is it safe to say that our non-www domain not working has affected our SEO, and if we fix it, will it improve things for us? Thank you so much for clarification on this issue.
Technical SEO | | JetBookMike0