htaccess help required

4 replies
Hello everyone.

Here is a breakdown on what I am trying to accomplish.

i own Example Web Page.

I have always used htaccess to redirect non-www to www for duplicate content issues.

I have been using a forum for 2 years in a subdomain forums.example.com with a vbulletin forum.

Many of these threads have PR, 25,000 indexed pages, etc, so I do not just want to delete the domain -- I want them all to be 301'd to my main domain page.

What is happening with my current code, is while it is redirecting

http://forums.example.com -> Example Web Page without a problem, the problem is when it is a thread being redirected.

for example this thread - - forums.example.com/showthread.php?t=5525

it will instead redirect to -- Example Web Page

I am not sure what is wrong with my code that is making that appear at the end, can anyone offer any insight?

I have left my code below :

Code:
RewriteEngine on +FollowSymLinks
rewritecond %{http_host} ^forums.example.com [nc]
rewriterule ^(.*)$ http://www.example.com/ [r=301,nc]
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$ [r=301,nc]
Thank you very much to anyone who can share some light.
#htaccess #required
  • Profile picture of the author Tashi Mortier
    Canonical Hostnames

    Description:
    The goal of this rule is to force the use of a particular hostname, in preference to other hostnames which may be used to reach the same site. For example, if you wish to force the use of Example Web Page instead of example.com, you might use a variant of the following recipe.
    Solution:
    For sites running on a port other than 80:

    RewriteCond %{HTTP_HOST} !^fully.qualified.domain.name [NC]
    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{SERVER_PORT} !^80$
    RewriteRule ^/(.*) http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R]
    And for a site running on port 80

    RewriteCond %{HTTP_HOST} !^fully.qualified.domain.name [NC]
    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]

    I just read through the official documentation. I think what you need is just the $1 which should contain the requested URL.

    Code:
    RewriteEngine on +FollowSymLinks
    rewritecond %{http_host} ^forums.example.com [nc]
    rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
    rewritecond %{http_host} ^example.com [nc]
    rewriterule ^(.*)$ http://www.example.com/$ [r=301,nc]
    or try this:

    Code:
    RewriteEngine on +FollowSymLinks
    rewritecond %{http_host} ^forums.example.com [nc]
    rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc,qsa]
    rewritecond %{http_host} ^example.com [nc]
    rewriterule ^(.*)$ http://www.example.com/$ [r=301,nc]
    QSA is for query string append which should add the ?post=380&thread=353 stuff.

    I have no webserver available for testing at the moment though, valuable resources are:

    mod_rewrite - Apache HTTP Server
    URL Rewriting Guide - Apache HTTP Server
    URL Rewriting Guide - Advanced topics - Apache HTTP Server
    Signature

    Want to read my personal blog? Tashi Mortier

    {{ DiscussionBoard.errors[2909000].message }}
    • Profile picture of the author JoeWunschSEO
      Hello Sir,

      I thank you for your support, but that is actually what I am trying not to do.

      I do not want to keep the forums, i do not want forums.example.com.com to become www.example.com/forums/

      I want it all redirect right to the homepage Example Web Page -- so that now there are no more forums.

      I have done that without a problem using my initial code, the only problem I am haivng is a when going to a forum page with a thread -- like

      http://forums.example.com/showthread.php?t=59076

      It is reffering it to : Example Web Page

      so as you can see it is leaving that last string at the end, it is removing the showthread.php part but leaving the ?t=59076


      This is causing my main page to show without a problem, but I am prty sure google can index all of these dynamic pages so I can't leave it like this.
      {{ DiscussionBoard.errors[2909146].message }}
      • Profile picture of the author IM Queen
        did you try this?
        Code:
        rewritecond %{http_host} ^forums.example.com$ [nc]
        Signature

        {{ DiscussionBoard.errors[2909213].message }}
  • Profile picture of the author SteveJohnson
    You need to put a question mark at the end of the first rewrite rule:

    Code:
    RewriteEngine on +FollowSymLinks
    rewritecond %{http_host} ^forums.example.com [nc]
    rewriterule ^(.*)$ http://www.example.com/? [R=301,NC,L]
    rewritecond %{http_host} ^example.com [nc]
    rewriterule ^(.*)$ http://www.example.com/$ [r=301,nc]
    The question mark tells Apache to not pass the existing query string.

    It also wouldn't hurt to throw an 'L' flag in there, since you don't really need any more rewriting for that particular URL. It's minuscule, but will save a bit of processor power.

    For more information: http://httpd.apache.org/docs/current...ml#rewriterule
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[2913762].message }}

Trending Topics