Page 8 of 18 FirstFirst 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 LastLast
Results 106 to 120 of 267
Like Tree3Likes

[How to] Setup www.yourdomain.com or yourdomain.com (www vs. non-www) - With .htaccess 301 redirects

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 ...

  1. #106
    Senior Member
    Real Name
    Cagatayh
    Join Date
    May 2007
    Location
    Seattle, WA
    Posts
    158
    Liked
    1 times
    Quote Originally Posted by Brian Cummiskey View Post
    If you are using a subdomain, you need to use different code in the subdomain folder. The root url (www.domain.com) should use the above code.

    and in the subdomain folder, use this in your htaccess:

    RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com
    RewriteRule (.*) http://subdomain.domain.com/$1 [L,R=301]
    Yep, it works now.
    Thanks a lot

  2. #107
    Member
    Real Name
    neo
    Join Date
    Oct 2008
    Posts
    85
    Liked
    0 times
    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.

  3. #108
    Senior Member
    Real Name
    Marco Mamdouh
    Join Date
    May 2008
    Location
    Egypt
    Posts
    2,627
    Liked
    1 times
    Blog Entries
    1
    Quote Originally Posted by neo_ View Post
    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.
    Try this
    Code:
    < %@ Language=VBScript %>        
      < %       
            Response.Status="301 Moved Permanently"        
            Response.AddHeader "Location", http://www.domain.com       
            %>
    Change domain.com with your domain

  4. #109
    Member
    Real Name
    neo
    Join Date
    Oct 2008
    Posts
    85
    Liked
    0 times
    Quote Originally Posted by marco1 View Post
    Try this
    Code:
    < %@ Language=VBScript %>        
      < %       
            Response.Status="301 Moved Permanently"        
            Response.AddHeader "Location", http://www.domain.com       
            %>
    Change domain.com with your domain
    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.

  5. #110
    Senior Member
    Real Name
    Marco Mamdouh
    Join Date
    May 2008
    Location
    Egypt
    Posts
    2,627
    Liked
    1 times
    Blog Entries
    1
    I'm not sure about that but most probably it will be before the end of rules
    Code:
    </rules>

  6. #111
    Member
    Real Name
    neo
    Join Date
    Oct 2008
    Posts
    85
    Liked
    0 times
    Does anyone know for 100% sure? I do not like editing code if I am not completely sure about it.

  7. #112
    vBSEO.com Webmaster Mert Gökçeimam's Avatar
    Real Name
    Lizard King
    Join Date
    Oct 2005
    Location
    Istanbul, Turkey, Turkey
    Posts
    22,367
    Liked
    542 times
    Blog Entries
    4
    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

  8. #113
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,782
    Liked
    648 times
    Blog Entries
    2
    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!


  9. #114
    Member
    Real Name
    neo
    Join Date
    Oct 2008
    Posts
    85
    Liked
    0 times
    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?

  10. #115
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,782
    Liked
    648 times
    Blog Entries
    2
    Ahh, i thought that's what you wanted Sorry 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!


  11. #116
    Member
    Real Name
    neo
    Join Date
    Oct 2008
    Posts
    85
    Liked
    0 times
    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.

  12. #117
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,782
    Liked
    648 times
    Blog Entries
    2
    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 guess i'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!


  13. #118
    Member
    Real Name
    neo
    Join Date
    Oct 2008
    Posts
    85
    Liked
    0 times
    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.

  14. #119
    Junior Member
    Real Name
    ADRAR
    Join Date
    May 2009
    Posts
    5
    Liked
    0 times
    tanks you

  15. #120
    Senior Member
    Real Name
    Darko
    Join Date
    Apr 2009
    Posts
    167
    Liked
    0 times
    So if I am using non www in google, should I do it also in .htaccess ?

Page 8 of 18 FirstFirst 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 LastLast

Similar Threads

  1. Urgent help with htaccess and 301 redirects
    By markbolyard in forum URL Rewrite Settings
    Replies: 4
    Last Post: 12-02-2007, 05:24 PM
  2. htaccess redirects when moving folder
    By I, Brian in forum Troubleshooting
    Replies: 3
    Last Post: 10-05-2007, 02:47 PM
  3. Help with initial htaccess setup
    By mhc1576 in forum URL Rewrite Settings
    Replies: 1
    Last Post: 12-28-2006, 07:44 AM
  4. Replies: 6
    Last Post: 10-23-2005, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •