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

XF 1.5 Redirects after vb3.8 import

#1
I can't seem to get my redirects set up properly after importing from vb3.8 to xenforo

vb3.8 was installed at http://www.example.com/forum

and Xenforo is installed at http://www.example.com/

I'm using the redirect scripts and they're working, but because I had to create the folder /forum to put them in, other pages in that directory need to be redirected as well like tags.php, search.php, memberlist.php, and other custom pages like all_albums.php. When I go to those pages now instead of getting the xenforo 404 error page, I get a page that just says:

Not Found
The requested URL /forum/memberlist.php was not found on this server.

I'm assuming this is because the directory exists but the files don't?

I've tried adding some redirects in the .htaccess files in both the root directory and the /forum directory but I can't seem to get it right.

My root directory .htacess file is the default one provided except I've added this to the top:
Code:
RedirectMatch 301 ^/forum/$ /forums/

# redirect to www
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R]
How can I redirect those other pages that used to exist in the /forum directory to their new pages in xenforo?
For example, I'd like to redirect forum/tags.php to /tags

The second issue relates to RedirectMatch 301 ^/forum/$ /forums/

I'm using Featured Threads as home page so I added the code above so http://www.example.com/forum would redirect to http://www.example.com/forums, but other pages in the directory wouldn't redirect so the scripts would still work.

Initially I wanted /forums to be /forum so I setup a route filter to redirect fourms/ to forum/ but then when I went to http://www.example.com/forum I would see a list of what was in the directory

Can I change /forums to /forum and still use the redirect scripts?

I hope I'm making sense! Thanks for taking the time to read this.
 

Jake Bunce

XenForo moderator
Staff member
#2
Keep the /forum directory with the redirect scripts. Then use this .htaccess file inside of /forum:

Code:
	RewriteEngine On

	# avoid possible conflict with XF's rules in the web root
	RewriteBase /forum

	# if file exists then do nothing (ie let php redirect scripts do their thing)
	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -l [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^.*$ - [NC,L]
	# else do a catch all redirect to the web root
	RewriteRule ^.*$ /? [R=301,L]
 

Jake Bunce

XenForo moderator
Staff member
#3
Can I change /forums to /forum and still use the redirect scripts?
The way that would have to be done is to remove the /forum directory, upload the php redirect scripts to the web root, then setup rewrite rules in the web root to capture the vB URLs in /forum and send them to the redirect scripts in the web root. It's a little awkward but is doable if you really want that.
 
#5
How can I redirect

This:
Code:
http://www.example.com/forum/album.php?albumid=944
To:
Code:
http://www.example.com/media/albums/944/
I tired this:
Code:
RewriteCond %{QUERY_STRING} (^|\?)albumid=([0-9]+)($|&)
RewriteRule ^album\.php$ /media/albums/%2/? [R=301,L]
Before the catch all in your code above, but I can't get it to work.
 

Mike

XenForo developer
Staff member
#6
Where specifically have you put it? Can you show the code?

What happens when you do to an old URL?
 
#7
This is the root folder:
Code:
RedirectMatch 301 ^/forum/$ /forums/

# redirect to www
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R]

redirect 301 /contact.html http://www.example.com/about.php
redirect 301 /tech.php http://www.example.com/

#    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 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 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 /xenforo

    #    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>
This is in /forum:
Code:
RewriteEngine On

# avoid possible conflict with XF's rules in the web root
RewriteBase /forum   

# if file exists then do nothing (ie let php redirect scripts do their thing)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# else do a catch all redirect to the web root
RewriteRule ^.*$ /? [R=301,L]
This is what I tried in /forum
Code:
RewriteEngine On

# avoid possible conflict with XF's rules in the web root
RewriteBase /forum   

# if file exists then do nothing (ie let php redirect scripts do their thing)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteCond %{QUERY_STRING} (^|\?)albumid=([0-9]+)($|&)
RewriteRule ^album\.php$ /media/albums/%2/? [R=301,L]

# else do a catch all redirect to the web root
RewriteRule ^.*$ /? [R=301,L]
I also tried this:
Code:
RewriteEngine On

# avoid possible conflict with XF's rules in the web root
RewriteBase /forum   

RewriteCond %{QUERY_STRING} (^|\?)albumid=([0-9]+)($|&)
RewriteRule ^album\.php$ /media/albums/%2/? [R=301,L]

# if file exists then do nothing (ie let php redirect scripts do their thing)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# else do a catch all redirect to the web root
RewriteRule ^.*$ /? [R=301,L]
When I click an old album url, it goes to the root page and not to the new album url.
 

Mike

XenForo developer
Staff member
#8
The last configuration should be the correct one. Is that what's currently in position?

I don't think it should interfere, but you may not need the RewriteBase line.

It might be worth removing the catch all at the end to make testing simpler.
 
#9
I used the last config and removed the catch all and it works! I then added the catch all back and it still works. Not sure what I did wrong last time I tried that, but thanks for helping out!
 
#10
Now that I have the albums redirected, now can I redirect the pictures?

How can I redirect:

This:
Code:
http://www.example.com/forum/picture.php?albumid=2741&pictureid=23505
To:
Code:
http://www.example.com/media/23505/full
?
 

Jake Bunce

XenForo moderator
Staff member
#11
Now that I have the albums redirected, now can I redirect the pictures?

How can I redirect:

This:
Code:
http://www.example.com/forum/picture.php?albumid=2741&pictureid=23505
To:
Code:
http://www.example.com/media/23505/full
?
Add these rules to the top of the .htaccess file in the /forum directory:

Code:
RewriteEngine On

RewriteCond %{QUERY_STRING} pictureid=([0-9]+)($|&)
RewriteRule ^picture\.php$ /media/%1/full? [R=301,L]
 
#12
Thanks Jake!

For anyone else converting from vb3.8, here's the final .htacess I'm using in the /forum directory to account for these three types of old urls:

http://www.example.com/forum/picture.php?albumid=2741&pictureid=23505
http://www.example.com/forum/album.php?albumid=472&pictureid=2967
http://www.example.com/forum/album.php?albumid=2678

Code:
RewriteEngine On

# avoid possible conflict with XF's rules in the web root
RewriteBase /forum

RewriteCond %{QUERY_STRING} pictureid=([0-9]+)($|&)
RewriteRule ^picture\.php$ /media/%1/full? [R=301,L]

RewriteCond %{QUERY_STRING} pictureid=([0-9]+)($|&)
RewriteRule ^album\.php$ /media/%1/full? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)albumid=([0-9]+)($|&)
RewriteRule ^album\.php$ /media/albums/%2? [R=301,L]

RewriteCond %{QUERY_STRING} tag=([a-z0-9_-]+)($|&)
RewriteRule ^tags\.php$ /tags/%1/? [R=301,L]

RewriteCond %{REQUEST_URI} tags.php
RewriteRule ^tags\.php$ /tags? [R=301,L]

RewriteCond %{REQUEST_URI} all_albums.php
RewriteRule ^all_albums\.php$ /media/albums? [R=301,L]


# if file exists then do nothing (ie let php redirect scripts do their thing)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# else do a catch all redirect to the web root
RewriteRule ^.*$ /? [R=301,L]
 
Last edited:
#14
Thanks Jake!

For anyone else converting from vb3.8, here's the final .htacess I'm using in the /forum directory to account for these three types of old urls:

http://www.example.com/forum/picture.php?albumid=2741&pictureid=23505
http://www.example.com/forum/album.php?albumid=472&pictureid=2967
http://www.example.com/forum/album.php?albumid=2678

Code:
RewriteEngine On

# avoid possible conflict with XF's rules in the web root
RewriteBase /forum

RewriteCond %{QUERY_STRING} pictureid=([0-9]+)($|&)
RewriteRule ^picture\.php$ /media/%1/full? [R=301,L]

RewriteCond %{QUERY_STRING} pictureid=([0-9]+)($|&)
RewriteRule ^album\.php$ /media/%1/full? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)albumid=([0-9]+)($|&)
RewriteRule ^album\.php$ /media/albums/%2? [R=301,L]

RewriteCond %{QUERY_STRING} tag=([a-z0-9_-]+)($|&)
RewriteRule ^tags\.php$ /tags/%1/? [R=301,L]

RewriteCond %{REQUEST_URI} tags.php
RewriteRule ^tags\.php$ /tags? [R=301,L]

RewriteCond %{REQUEST_URI} all_albums.php
RewriteRule ^all_albums\.php$ /media/albums? [R=301,L]


# if file exists then do nothing (ie let php redirect scripts do their thing)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# else do a catch all redirect to the web root
RewriteRule ^.*$ /? [R=301,L]

Hi @Travis-Mc

Thank You so much. I am exactly facing the same problem (with TAGS) and your code helped a bit.

I would like to add few points.

1) In vBulletin, the Tag can have Capital Letters. I think your code is not handling that.

This may work (adding Capital Letters) :

Code:
RewriteCond %{QUERY_STRING} tag=([a-zA-Z0-9_-]+)($|&)
2) Your code works for single word Tags. How do you handle the tags with 2 or more words ?

For eg,

How do you convert ?

Code:
http://www.domain.com/forum/tags.php?tag=Bigdata+Walk-In
to

Code:
http://www.domain.com/tags/bigdata-walk-in/
any help will be appreciated.
 
Last edited: