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

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

Try this?

RewriteCond %{HTTP_HOST} ^(www\.)?deltaprintr.com$ [NC]
RewriteRule ^/?forums/(.*)$ http://forums.deltaprintr.com/$1 [L,R=301]
 
Here's the full .htaccess file before I added the above code to it.


# 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
Think maybe this could be causing some issue? ;)
 
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.
 
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>
 
Top Bottom