1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to re-direct old links to new sub-domain?

Discussion in 'Server Configuration and Hosting' started by Delta3D, Oct 3, 2015.

  1. Delta3D

    Delta3D Member

    We moved our forums from domain.com/forums to forums.domain.com. All the links that users previously posted on our forums to link to other forum posts are now broken because they point to domain.com/forums. How can I fix it so that when someone clicks on a link that starts with domain.com/forums, gets redirected to forums.domain.com ?

    Appreciate the help!
     
  2. Mouth

    Mouth Well-Known Member

    You would need to configure your web server with a redirect
     
  3. Delta3D

    Delta3D Member

    I tried adding this to the .htaccess located in the forums directory, but it does nothing:

    RewriteEngine ON
    RewriteCond %{REQUEST_URI} ^/forums
    RewriteRule ^(.*)$ http://forums.deltaprintr.com/$1 [R=301,L]

    Instead it takes me to a page at deltaprintr.com/forums. We run a wordpress on our domain root and forums at public_html/forums.
     
  4. Delta3D

    Delta3D Member

    Here's the full .htaccess file before I added the above code to it.

    # Mod_security can interfere with uploading of content such as attachments. If you
    # cannot attach files, remove the "#" from the lines below.
    #<IfModule mod_security.c>
    # SecFilterEngine Off
    # SecFilterScanPOST Off
    #</IfModule>

    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 500 default

    <IfModule mod_rewrite.c>
    RewriteEngine On

    # If you are having problems with the rewrite rules, remove the "#" from the
    # line that begins "RewriteBase" below. You will also have to change the path
    # of the rewrite to reflect the path to your XenForo installation.
    RewriteBase /forum

    # This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    </IfModule>
    RewriteCond %{HTTP_HOST} ^forums\.deltaprintr\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.forums\.deltaprintr\.com$
    RewriteRule ^/?$ "http\:\/\/www\.deltaprintr\.com\/forums" [R=301,L]
     
  5. Mouth

    Mouth Well-Known Member

    Try this?

    RewriteCond %{HTTP_HOST} ^(www\.)?deltaprintr.com$ [NC]
    RewriteRule ^/?forums/(.*)$ http://forums.deltaprintr.com/$1 [L,R=301]
     
  6. Tracy Perry

    Tracy Perry Well-Known Member

    Think maybe this could be causing some issue? ;)
     
  7. Delta3D

    Delta3D Member

    That's part of the default setup, I don't think I should be editing that?
     
  8. Tracy Perry

    Tracy Perry Well-Known Member

    Just caught (sorry, was late at night when I was reading that) that your forum is NOT in the root, it is actually in /forum. I'd change that to /community because otherwise you are goign to get /forum/forums in your slug - but that's just me.
     
  9. ForumCube

    ForumCube Active Member

    You should place your rewrite rules inside re-write condition. Try following code in your root domain location:

    Code:
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 500 default
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    
    #You were using /forum as base which is actually wrong in your case
    RewriteBase /
    
    # This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    
    #below line will simply take care of the redirect with proper redirect code
    RedirectMatch 301 ^/forums/(.*)$ http://forums.deltaprintr.com/$1
    
    </IfModule>
     

Share This Page