This is a discussion on [How to] Setup www.yourdomain.com or yourdomain.com (www vs. non-www) - With .htaccess 301 redirects within the General Discussion forums, part of the vBSEO SEO Plugin category; Originally Posted by Brian Cummiskey If you are using a subdomain, you need to use different code in the subdomain ...
Hi, I want to use this but I do not use a .htaccess file. I use IIS7 URL Rewrite, so I use a web.config file.
What is the properly phrased code that I should use for a non-www rewrite?
Thanks in advance.
For reffrence, here is what my web.config file looks like. Do I add it anywhere inside, and if so in between what tags? Or should I just add it at the end after everything?
Code:<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Imported Rule 1" enabled="true" stopProcessing="true"> <match url="^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$" ignoreCase="false" /> <action type="Rewrite" url="vbseo_sitemap/vbseo_getsitemap.php?sitemap={R:1}" appendQueryString="false" /> </rule> <rule name="Imported Rule 2" enabled="true" stopProcessing="true"> <match url="^((archive/)?(.*\.php(/.*)?))$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{URL}" negate="true" pattern="(admincp/|modcp/|cron|vbseo_sitemap)" ignoreCase="false" /> </conditions> <action type="Rewrite" url="vbseo.php" appendQueryString="true" /> </rule> <rule name="Rewrite All" enabled="true" stopProcessing="true"> <match url="^.*$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" negate="true" pattern="/(admincp|modcp|clientscript|cpstyles|images)/" ignoreCase="false" /> </conditions> <action type="Rewrite" url="vbseo.php" appendQueryString="true" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
Thanks in advance.
I'm not sure about that but most probably it will be before the end of rules
Code:</rules>
Does anyone know for 100% sure? I do not like editing code if I am not completely sure about it.
Please add the following right after first <rules> line
PHP Code:<rule name="Enforce Hostname" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^example\.net$" />
</conditions>
<action type="Redirect" url="http://example.net/{R:0}" redirectType="Permanent" />
</rule>
Mert Gökçeimam / Crawlability Inc.
vBSEO 3.6.0 Alpha Önizlemesi - Including Like Tree
Unveiling the NEW vBSEO Sitemap Generator 3.0 - available NOW for vBSEO Customers!
Twitter:@Depkac
Personal Blog : Mert Gökçeimam
If mert's solution doesn't work for you, try this:
Code:<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="WWW Rewrite" enabled="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> </conditions> <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" /> </rule> <rule name="Imported Rule 1" enabled="true" stopProcessing="true"> <match url="^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$" ignoreCase="false" /> <action type="Rewrite" url="vbseo_sitemap/vbseo_getsitemap.php?sitemap={R:1}" appendQueryString="false" /> </rule> <rule name="Imported Rule 2" enabled="true" stopProcessing="true"> <match url="^((archive/)?(.*\.php(/.*)?))$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{URL}" negate="true" pattern="(admincp/|modcp/|cron|vbseo_sitemap)" ignoreCase="false" /> </conditions> <action type="Rewrite" url="vbseo.php" appendQueryString="true" /> </rule> <rule name="Rewrite All" enabled="true" stopProcessing="true"> <match url="^.*$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_FILENAME}" negate="true" pattern="/(admincp|modcp|clientscript|cpstyles|images)/" ignoreCase="false" /> </conditions> <action type="Rewrite" url="vbseo.php" appendQueryString="true" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
Brian Cummiskey / Crawlability Inc.
vBSEO 3.6.0 GOLD Released!
Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!
Thanks Brian and Mert.
I ended up using Mert's code. The code Brian provided me with actually does the opposite of what I wanted, and adds a www to my domain when I type it without the "www".
But I am curious if weather the code Brian provided me is more cleaner since I don't have to manually edit the code with my domain. Could you provide me with a revised code for non-www?
Ahh, i thought that's what you wantedSorry i mis-read.
basically, need to switch out the negate test to false and remove the www's from the redirect.
untested:
edit: doesn't work.
Last edited by Brian Cummiskey; 09-17-2009 at 02:47 AM.
Brian Cummiskey / Crawlability Inc.
vBSEO 3.6.0 GOLD Released!
Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!
Now that I re-read my original post I do not blame you for making that mistake as I was not clear enough.
But I just tested your new code and it brought my site down whenever I entered in www.domain.com
Firefox gave me this error message:
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
Hrm, i'll have to do more reasearch... it's probably not matching the rule properly. Again, i don't have an iis server to test on, so it was a guessi'll see if i can come up with a better soloution. In the meantime, use mert's method.
Brian Cummiskey / Crawlability Inc.
vBSEO 3.6.0 GOLD Released!
Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!
Yes, please let me know when you further look into refining your code.
I am using Brian's code on one of my forums and it works fine.
For my other forum that is heavily customized, it seems to cause posting errors.
tanks you
So if I am using non www in google, should I do it also in .htaccess ?