XF 1.3 Switching domain, keeping old one, redirects

Floyd R Turbo

Well-known member
I wish to change my xenforo domain from olddomain.com to newdomain.com, and then use olddomain.com for another purpose.

I was told by my host that the first part is simple, but the second part might be difficult because the redirect script would prevent traffic from getting to olddomain.com. It will probably be a month or two before I would want to start using olddomain.com for anything (product sales site).

So would this be possible with a well-written redirect script?
 
It is possible. The redirect needs to target specific URLs. For example, if XF was/is in your web root on both domains then you would add these rules to the top of the .htaccess file in the web root of olddomain.com:

Code:
RewriteEngine On

RewriteRule ^(threads|forums|members)/(.*)$ http://www.newdomain.com/$1/$2 [R=301,L]

That will redirect only /threads /forums /members URLs which would all belong to XF. You can add to that list to include other XF URLs.

The only real consideration here is if the new site on olddomain.com is using any of those same paths, then you would have a conflict that may require more precise rules to resolve.
 
The oldforum would probably only resolve to an index page, and then a cart. Possibly only the cart (Magento).

So if the root of the current site resolves to the main forum page, and I would want this to resolve to the cart after the transition, is this the kind of conflict you are referring to @Jake Bunce?
 
The oldforum would probably only resolve to an index page, and then a cart. Possibly only the cart (Magento).

So if the root of the current site resolves to the main forum page, and I would want this to resolve to the cart after the transition, is this the kind of conflict you are referring to @Jake Bunce?

Well no. I am talking about similar URLs that share the same path such as /threads. The example you gave is of identical URLs which cannot be resolved. In that case the web root of the forum simply would not be redirected.
 
Ah. So I would need to perhaps have a splash page on the root of olddomain.com with a link to the forum main page at newdomain.com, and then any attempts to access any forum content would automatically redirect - correct?
 
Yep, in looking through my site I have seen also categories, portal, online, watched, search, recent-activity, find-new, etc. I don't see anything for posts or attachments though.

Seems the list would be rather large if I would be trying to capture all the possibilities.

Would it be possible to look at this the other way around? All I need to not redirect is the root URL. Is there a way to redirect everything else except the root, which would be directed to a selection page?
 
Ok, so let's get specific here. I have 2 .htaccess files. One in the root, one in my old vb4 directory.

Here is the root .htaccess

Code:
#    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
  


        RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.olddomain.com/$1 [R,L]

    #make exception for XF's thread URL format
    RewriteRule ^threads/[^\.]+\.[0-9]+/ - [S=1]
    #redirect vB's thread URL format
    RewriteRule ^threads/([0-9]+)-.*$ /threads/$1? [R=301,L]


    #    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


    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>

Here is the vb4 redirect

Code:
#    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
  
RewriteCond %{QUERY_STRING} (^|\?)([0-9]+)-([a-zA-Z0-9_\-]+)
RewriteRule ^vb4/showthread.php /showthread.php?t=%2 [R=301,L]

        RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.olddomain.com/$1 [R,L]



    #    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


    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>

I created a very much simple html page for the root of olddomain. However, I will not immediately have olddomain up and running so a temporary total redirect would be possible, but not sure that is the 'right' thing to do, at least not in the long run anyways.

So if I understand this correctly, I will need to change olddomain to newdomain in the existing .htaccess files above, then add

Code:
RewriteRule ^(threads|forums|members)/(.*)$ http://www.newdomain.com/$1/$2 [R=301,L]

or perhaps

Code:
RewriteRule ^(categories|portal|online|watched|search|recent-activity|find-new|threads|forums|members)/(.*)$ http://www.newdomain.com/$1/$2 [R=301,L]

But at what point? Is there a line I need to remove from my .htaccess file(s)?

I transitioned from vb to xf in november of last year after the forum had been up for about a year or so. Pretty small forum all things considered, and I did not write the .htaccess files so any suggestions are welcome.

Thanks
Bud
 
Would it be possible to look at this the other way around? All I need to not redirect is the root URL. Is there a way to redirect everything else except the root, which would be directed to a selection page?

To match all except the root URL, add these rules to the top of the .htaccess file in the web root of olddomain.com::

Code:
RewriteEngine On

RewriteRule ^$ - [S=2]
RewriteRule ^index\.php$ - [S=1]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

The first two rules cause it to skip:

olddomain.com/
olddomain.com/index.php

Then the last rule redirects everything else to the new domain.
 
The .htaccess file in your old vB directory can remain. It can be copied over to the newdomain with all of the other files.

The one .htaccess file in the root of the olddomain will redirect all requests to the new domain at which point the vB redirects on the newdomain will redirect again. It's just one more layer of redirect. You only need to be sure to update the domain names in the .htaccess files that you copy over.
 
So this would be the "cleaned up" version of my redirect in the/newdomain.com/vb4 directory:

Code:
ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{QUERY_STRING} (^|\?)([0-9]+)-([a-zA-Z0-9_\-]+)
    RewriteRule ^vb4/showthread.php /showthread.php?t=%2 [R=301,L]

    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R,L]
    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>

Then in olddomain.com/ (root):

Code:
ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default

<IfModule mod_rewrite.c>
    RewriteEngine On

#redirect all but root and index to newdomain
    RewriteRule ^$ - [S=2]
    RewriteRule ^index\.php$ - [S=1]
    RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]
#note: I changed the above line to https and I run SSL

#redirect http to https
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R,L]

#make exception for XF's thread URL format
    RewriteRule ^threads/[^\.]+\.[0-9]+/ - [S=1]
#redirect vB's thread URL format
    RewriteRule ^threads/([0-9]+)-.*$ /threads/$1? [R=301,L]

    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>

But then would I also have this in the root of newdomain?

Code:
ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default

<IfModule mod_rewrite.c>
    RewriteEngine On

#redirect http to https
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R,L]

#make exception for XF's thread URL format
    RewriteRule ^threads/[^\.]+\.[0-9]+/ - [S=1]
#redirect vB's thread URL format
    RewriteRule ^threads/([0-9]+)-.*$ /threads/$1? [R=301,L]

    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>

On one hand I think the answer is yes, because if someone hits newdomain.com and there is no .htaccess file, that's bad. But if they hit olddomain.com and the redirected, isn't there something about having too many .htaccess files creating conflict problems? I know that the person who set up my vb4 redirect had mentioned that. Just checking.
 
Also I'm wondering if I have a few unnecessary lines. Since I have the .htaccess file in the /vb4 directory, do I need this line at all in either of the root .htaccess files?

Code:
#redirect vB's thread URL format
    RewriteRule ^threads/([0-9]+)-.*$ /threads/$1? [R=301,L]
 
I would stick with my previous instructions.

Yes, there are some things in your current htaccess files that look unnecessary. It won't necessarily break anything. It is difficult to do a full review without all of the information, such as what is the format of your vB URLs? Then I can know if some of those existing vB redirects are unnecessary.
 
I edited this post to clarify a few things...

Post # 16 is the modified .htaccess files per your instructions. The only other thing I did was remove most of the # comment lines. Sorry if that made it difficult to follow what I did, so here is a summary:

A) the vb4 .htaccess file is exactly the same, only that olddomain was changed to newdomain
B) the olddomain .htaccess file has the lines added per your recommendation (with newdomain vs olddomain)
C) the newdomain .htaccess file is the same as the original olddomain .htaccess file (with newdomain vs olddomain)

My questions were

1) do I have the first 2 files correct (vb4 dir, and olddomain root dir) - I believe these are correct

and most importantly, I want to know:

2) do I need the .htaccess file in the newdomain dir (and do I have it right)?

...such as what is the format of your vB URLs? Then I can know if some of those existing vB redirects are unnecessary.

It was a standard vb4 install into the directory olddomain.com/vb4. I don't know if that helps at all. That was my first foray into forum administration so there was nothing special about the URL formatting as far as I can recall.

It's been a while since I switched from vb so I could probably drop that entire line of redirect action thinking out completely. I think it was mainly so that search engine links resolved, not so much for end-user bookmarks or links from other forums. But I guess it doesn't hurt to keep it, like you said, it won't break anything.
 
Last edited:
Back
Top Bottom