Results 1 to 13 of 13

Different 301 Redirect formats

This is a discussion on Different 301 Redirect formats within the General Discussion forums, part of the vBulletin SEO Discussion category; Hi, Since you guys are the rewrite kings, Can anyone explain the differences between these two different 301 redirect statements ...

  1. #1
    Junior Member oddmusic's Avatar
    Real Name
    John
    Join Date
    Nov 2006
    Posts
    10
    Liked
    0 times

    Different 301 Redirect formats

    Hi,

    Since you guys are the rewrite kings, Can anyone explain the differences between these two different 301 redirect statements below please. This is only to redirect "domain.com" to "www . domain.com" to consolidate links. They both seem to do the same thing, but the vBSEO folks recommended the first one, and I was using the second one before setting up a forum in a sub-directory of my website, so I'd like to know the differences and if one way is better, etc.

    The redirect is in my root dir .htaccess file, and not my in my /forum subdirectory. They both also work fine when accessing the forum with either "forum.domain.com" or "www . domain.com/forum" or "domain.com/forum" so I have not modified my .htaccess file in the /forum directory to do any custom re-writing as far as "www / non-www" stuff goes, so I'll leave that file alone for now.

    Here's the two different versions:

    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

    RewriteCond %{http_host} ^domain.com [nc]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,nc]

    Which one is preferred? Both the same?

    On another different note, when I type: forum.domain.com or domain.com/forum/ (with trailing slash) both of those urls stay the same in the browser heading, and once a click is made on anything, it changes to "www . domain.com/forum" because the url's are already re-written. If I go to domain.com/forum (without the slash) it gets re-written right away to "www . domain.com/forum". I don't think there is any issue with that, since the first two get changed to the preferred format "www.domain.com/forum" once any action is taken by the user, unless you think I should have rewrites for that?

    Thanks!

  2. #2
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Hello John,

    [NC] attribute means case-insensitive comparison, but in this case it is not required since hostname is always provided in lower case.
    [L] attribute mean last rule - so redirect is applied immediately, no further rewrite rules are processed in .htaccess
    On another different note, when I type: forum.domain.com or domain.com/forum/ (with trailing slash) both of those urls stay
    You should insert similar rewrite rule in forum/.htaccess file right after "RewriteEngine on" line:

    Code:
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule (.*) http://www.domain.com/forum/$1 [R=301,L]
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  3. #3
    Junior Member oddmusic's Avatar
    Real Name
    John
    Join Date
    Nov 2006
    Posts
    10
    Liked
    0 times
    Quote Originally Posted by Oleg Ignatiuk View Post
    You should insert similar rewrite rule in forum/.htaccess file right after "RewriteEngine on" line:

    Code:
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule (.*) http://www.domain.com/forum/$1 [R=301,L]
    Thanks, Oleg. The one problem it's having with those rules in the forum .htaccess file is that if I type: domain.com/forum (without a trailing slash) I get a 404 error.

    Works great for forum.domain.com and domain.com/forum/

    Do I need a separate rule to catch that one?

  4. #4
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Try to add another rewrite rule to the root .htaccess for that:
    Code:
    RewriteRule ^forum$ http://www.domain.com/forum/ [R=301,L]
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  5. #5
    Junior Member oddmusic's Avatar
    Real Name
    John
    Join Date
    Nov 2006
    Posts
    10
    Liked
    0 times
    Quote Originally Posted by Oleg Ignatiuk View Post
    Try to add another rewrite rule to the root .htaccess for that:
    Code:
    RewriteRule ^forum$ http://www.domain.com/forum/ [R=301,L]
    Getting closer, but that rule (in either root or /forum .htaccess) causes the rewrite to do this:

    HTML Code:
    www.domain.com/forum//home/username/public_html/forum
    giving a 404

  6. #6
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Try changing it to:
    Code:
    RewriteRule ^forum$ http://www.domain.com/forum/? [R=301,L]
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  7. #7
    Junior Member oddmusic's Avatar
    Real Name
    John
    Join Date
    Nov 2006
    Posts
    10
    Liked
    0 times
    Still was getting the 404. I was seeing some strangeness messing around with a couple things, like logging in, then removing the "www" from the url, and then it looked like I was not logged in. So, starting from scratch, and getting rid of a couple things, taking the sub-domain out of the picture as well for now (forum . domain.com) to have a clean slate, so nothing extra in the /forum .htaccess at the moment other than the defaults.

    Here's what's there now, and what's working and not working:

    In the website root .htaccess file for non-www redirection to www for main website (not forum based)
    Code:
    ############
    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
    ############
    This causes redirects for non-www url's to get changed to www
    Works fine for the website, and also does a perfect redirect for domain.com/forum (with no trailing slash) which gets redirected to: www .domain.com/forum/

    All good so far, but if I go to: domain.com/forum/ (with trailing slash) it does not redirect at all.

    All of the URLs on the page point to www .domain.com so it does not really seem like that big of a deal, but I noticed that if you log in (with the page not redirected) it looks like you are not logged in at all even though you are. If you click on a link or thread, then you will see you are logged in, because the links have the proper url's in them, but if you just reload the page with clicking on anything, it doesn't look like you are logged in (no welcome message, guest browsing message is on, etc)

    And also, if I'm logged in fine as Admin or User, and I take away the "www" from the url and reload the page, it also looks like I'm not logged in, and browsing the forum as a guest. But, if I leave it with the "www" and still looking like I'm not logged in, and just take away the trailing slash, and then reload the page, it redirects fine again and shows I'm still logged in.

    So looks like the one thing I need to get going is proper redirection of domain.com/forum/ (with slash) to --> www .domain.com/forum/

    and it's that trailing slash that's killing me

    Anyway, sorry for all the junk here, just trying to get things going, and thanks for the help so far.
    Last edited by oddmusic; 11-20-2006 at 02:49 AM.

  8. #8
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    All good so far, but if I go to: domain.com/forum/ (with trailing slash) it does not redirect at all.
    If you have .htaccess in the forum folder (I'm assuming you have vBSEO's .htaccess in it), you need corresponding rewrite rules in it as well (as I described in the post above).
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  9. #9
    Junior Member oddmusic's Avatar
    Real Name
    John
    Join Date
    Nov 2006
    Posts
    10
    Liked
    0 times
    Quote Originally Posted by Oleg Ignatiuk View Post
    If you have .htaccess in the forum folder (I'm assuming you have vBSEO's .htaccess in it), you need corresponding rewrite rules in it as well (as I described in the post above).
    Here's what I get with these rules in the root .htaccess:
    ############
    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
    ############
    and with these rules (below) in the /forum .htaccess file. I tried with the one rule, then the other, then both, then both reversed, and also with the rule you mentioned also putting in the root .htaccess folder, and the results I get with different combinations are:
    Code:
    - - -
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule ^forum$ http://www.domain.com/forum/ [R=301,L]
    
    domain.com/forum   - good redirect
    domain.com/forum/  - no redirect
    www.domain.com/forum  works fine with or without trailing slash
    - - -
    
    - - - 
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule (.*) http://www.domain.com/forum/$1 [R=301,L]
    
    domain.com/forum    - 404   http://www.domain.com/forum//home/username/public_html/forum
    domain.com/forum/  - good redirect
    www.domain.com/forum   works fine with or without trailing slash
    - - - 
    
    - - -
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule (.*) http://www.domain.com/forum/$1 [R=301,L]
    RewriteRule ^forum$ http://www.domain.com/forum/ [R=301,L]
    
    domain.com/forum     - 404  http://www.domain.com/forum//home/username/public_html/forum
    domain.com/forum/  - good redirect
    www.domain.com/forum   works fine with or without trailing slash
    - - - 
    
    - - -
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteRule ^forum$ http://www.domain.com/forum/ [R=301,L]
    RewriteRule (.*) http://www.domain.com/forum/$1 [R=301,L]
    
    domain.com/forum     - 404  http://www.domain.com/forum//home/username/public_html/forum
    domain.com/forum/   - puts http://www.domain.com/forum/ in browser window, tries to do redirect
    but doesn't come up.  Firefox browser says: Firefox has detected that the server is redirecting
    the request for this address in a way that will never complete.  IE browser just spins
    
    www.domain.com/forum  - 404 http://www.domain.com/forum//home/username/public_html/forum
    
    www.domain.com/forum/  - tries to do redirect but doesn't come up.  
    Firefox browser says: Firefox has detected that the server is redirecting the request
    for this address in a way that will never complete.  IE browser just spins
    - - -

  10. #10
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Ok, try to change rewrite rules in forum/.htaccess to:
    Code:
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteCond %{THE_REQUEST} forum/
    RewriteRule (.*) http://www.domain.com/forum/$1 [R=301,L]
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  11. #11
    Junior Member oddmusic's Avatar
    Real Name
    John
    Join Date
    Nov 2006
    Posts
    10
    Liked
    0 times
    You the Man, Oleg. That one did the trick. Thanks!!

    -- John

  12. #12
    vBSEO Staff Oleg Ignatiuk's Avatar
    Real Name
    Oleg Ignatiuk
    Join Date
    Jun 2005
    Location
    Belarus
    Posts
    25,689
    Liked
    157 times
    Great!
    Oleg Ignatiuk / Crawlability Inc.
    vBSEO 3.6.0 GOLD Released!
    Unveiling the NEW vBSEO Sitemap Generator 3.0. - available NOW for vBSEO Customers!


  13. #13
    Senior Member
    Real Name
    Joseph Ward
    Join Date
    Jun 2005
    Posts
    23,847
    Liked
    32 times
    Blog Entries
    9

Similar Threads

  1. 301 redirect 404 pages?
    By Steve in forum Off-Topic & Chit Chat
    Replies: 13
    Last Post: 04-27-2009, 02:29 AM
  2. 301 fügt ?vbseourl= mit an
    By Junior in forum Deutsch
    Replies: 8
    Last Post: 11-20-2006, 02:07 PM
  3. 301 Redirect Original Content (posts)
    By thecat in forum Troubleshooting
    Replies: 2
    Last Post: 10-04-2006, 11:00 AM
  4. General 301 Redirect / Regular Expression Request
    By GateKeeper in forum URL Rewrite Settings
    Replies: 0
    Last Post: 06-17-2006, 12:27 PM
  5. Stuck setting up a 301 redirect
    By Pixalo in forum URL Rewrite Settings
    Replies: 3
    Last Post: 06-06-2006, 06:36 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
  •