Use .htaaccess and mod_rewrite to handle sub-domains effectively.

Discussion in 'Apache' started by SaN-DeeP, Sep 3, 2005.

  1. #1
    I am running couple of sub-domains via our main domain: http://www.techarena.in

    Sub-domains in use:
    http://forums.techarena.in
    http://gallery.techarena.in

    Here are the contents of my current .htaacess file:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^207\.58\.143\.178$
    RewriteRule ^/?(.*)$ http://www.techarena.in/$1 [R=301,L,NS]
    
    ErrorDocument 400 /
    ErrorDocument 401 /
    ErrorDocument 403 /
    ErrorDocument 404 /
    ErrorDocument 500 /
    
    RewriteCond %{HTTP_HOST} ^techarena\.in
    RewriteRule ^(.*)$ http://www.techarena.in/$1 [R=permanent,L]
    Code (markup):
    I am re-directing all the traffic from our Domain IP to domain via above code, and also re-directing all the 404 and/or error pages to main URL:

    Problem 1 - check this url, entire CSS is misplaced.
    http://www.techarena.in/adsd/inde
    How do i fix this problem ?

    Problem 2 - Crawlers are re-directing content from foll. dirs as well:
    www.techarena.in/forums/
    www.techarena.in/gallery/
    I want to prohibit this using 301 re-directs (please note, there is lot of content already indexed using the above URLs)
    I want to re-direct all the traffic coming from www.techarena.in/forums/ to http://forums.techarena.in
    and re-direct all the traffic coming from www.techarena.in/gallery/ to http://gallery.techarena.in

    so any user going to this thread:
    http://www.techarena.in/forums/showthread.php?t=346155 should be automatically re-directed to http://forums.techarena.in/showthread.php?t=346155

    Problem 3:
    check the following URL:
    http://forums.techarena.in/ads/sdsdd
    How badly the same gets displayed (because of unknown image paths and .css file not found) how to manage the same as well ?


    Question 1
    Should i do some modifications for .htaacess files in my subdomain DIRs as well ? those are currently blank.

    Thanks in Advance.
    Regards,
    SaN-DeeP
     
    SaN-DeeP, Sep 3, 2005 IP
  2. minstrel

    minstrel Illustrious Member

    Messages:
    15,082
    Likes Received:
    1,243
    Best Answers:
    0
    Trophy Points:
    480
  3. SaN-DeeP

    SaN-DeeP Well-Known Member

    Messages:
    590
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #3
    sorry to bump back the thread again, accidentally created 2 topics
    I am still waiting for an effective solution.
     
    SaN-DeeP, Feb 28, 2006 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    For #1 and 3, you have to change the image paths and .css code as if the new URL is the actual URL. The browsers don't know there fake URLs. I'm a css n00bie.

    For #2

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^gallery/([^.]+)$ http://gallery.techarena.in/$1/ [R=301,L]
    RewriteRule ^forums/([^.]+)$ http://forums.techarena.in/$1/ [R=301,L]
    RewriteCond %{HTTP_HOST} ^207\.58\.143\.178$
    RewriteRule ^/?(.*)$ http://www.techarena.in/$1 [R=301,L,NS]

    ErrorDocument 400 /
    ErrorDocument 401 /
    ErrorDocument 403 /
    ErrorDocument 404 /
    ErrorDocument 500 /

    RewriteCond %{HTTP_HOST} ^techarena\.in
    RewriteRule ^(.*)$ http://www.techarena.in/$1 [R=permanent,L]
     
    Nintendo, Feb 28, 2006 IP
  5. SaN-DeeP

    SaN-DeeP Well-Known Member

    Messages:
    590
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #5
    the above .htaacess is not working :confused:
    this are the content of my .htacess in root folder /
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^gallery/([^.]+)$ http://gallery.techarena.in/$1/ [R=301,L]
    RewriteRule ^forums/([^.]+)$ http://forums.techarena.in/$1/ [R=301,L]
    RewriteCond %{HTTP_HOST} ^207\.58\.143\.178$
    RewriteRule ^/?(.*)$ http://www.techarena.in/$1 [R=301,L,NS]
    
    ErrorDocument 400 /
    ErrorDocument 401 /
    ErrorDocument 403 /
    ErrorDocument 404 /
    ErrorDocument 500 /
    
    RewriteCond %{HTTP_HOST} ^techarena\.in
    RewriteRule ^(.*)$ http://www.techarena.in/$1 [R=permanent,L]
    Code (markup):
    this is the content of .htaccess in /forums folder
    Options +Indexes
    Options +FollowSymlinks
    
    ErrorDocument 400 /
    ErrorDocument 401 /
    ErrorDocument 403 /
    ErrorDocument 404 /
    ErrorDocument 500 /
    Code (markup):
     
    SaN-DeeP, Mar 1, 2006 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    You can get rid of the

    /forums/.htaccess

    file.

    Is

    http://www.techarena.in/.htaccess

    where the code's at?? It looks like the

    ErrorDocument 404

    has it, like that URL doesn't exist.

    Do any sites link to your IP address? If not,

    RewriteCond %{HTTP_HOST} ^207\.58\.143\.178$
    RewriteRule ^([^.]+)$ http://www.techarena.in/$1 [R=301,L,NS]

    should be taken out.

    What is

    RewriteCond %{HTTP_HOST} ^techarena\.in
    RewriteRule ^(.*)$ http://www.techarena.in/$1 [R=permanent,L]

    for?


    http://www.techarena.in/.htaccess

    ErrorDocument 400 /
    ErrorDocument 401 /
    ErrorDocument 403 /
    ErrorDocument 404 /
    ErrorDocument 500 /
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^gallery/([^.]+)$ http://gallery.techarena.in/$1 [R=301,L]
    RewriteRule ^forums/([^.]+)$ http://forums.techarena.in/$1 [R=301,L]

    if you can have the RewriteCond stuff out of there.

    And it was missing the

    RewriteBase /

    code.
     
    Nintendo, Mar 1, 2006 IP
  7. SaN-DeeP

    SaN-DeeP Well-Known Member

    Messages:
    590
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #7
    Thanks for helping out till here:
    this is my current .htaacess file

    ErrorDocument 400 /
    ErrorDocument 401 /
    ErrorDocument 403 /
    ErrorDocument 404 /
    #
    Options +Indexes +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    #
    # Prevent duplicate content on gallery and forums subdomain
    RewriteCond %{HTTP_HOST} ^(gallery¦forums)\.techarena.in
    RewriteRule ^(gallery¦forums)/[^.]+$ - [F]
    #
    # Redirect gallery and forums subdirectories to subdomains
    RewriteCond %{HTTP_HOST} ^www\.techarena\.in
    RewriteRule ^gallery/([^.]+)$ http://gallery.techarena.in/$1/ [R=301,L]
    RewriteCond %{HTTP_HOST} ^www\.techarena\.in
    RewriteRule ^forums/([^.]+)$ http://forums.techarena.in/$1/ [R=301,L]
    #
    RewriteCond %{HTTP_HOST} ^207\.58\.143\.178 [OR]
    RewriteCond %{HTTP_HOST} ^techarena\.in
    RewriteRule (.*) http://www.techarena.in/$1 [R=permanent,L]
    Code (markup):
    Replacing the same with the last provided by you, still wont make any effect.

    Lot of site content is indexed in google via the IP Adress, hence need to convert any request coming from SERPs via IP to the correct URL.

    since site should be indexed via techarena.in I have added additional .htaacess codes to get it re-directed to www.techarena.in

    I tried deleting .htacess files from /forums /gallery folder as well.

    Regards,
     
    SaN-DeeP, Mar 3, 2006 IP