.htaccess redirection help

imthebest

Well-known member
Hi guys,

I need help to redirect everything from:

Code:
http://www.mysite.com/forums/tags.php
http://www.mysite.com/forums/tags.php?tag=videos
http://www.mysite.com/forums/tags.php?tag=videos&page=2
http://www.mysite.com/forums/tags.php?tag=funny+stuff
http://www.mysite.com/forums/tags.php?tag=funny+stuff&page=2

to:

Code:
http://www.mysite.com/forums/tags/
http://www.mysite.com/forums/tags/videos/
http://www.mysite.com/forums/tags/videos/page-2
http://www.mysite.com/forums/tags/funny+stuff/
http://www.mysite.com/forums/tags/funny+stuff/page-2

How I can do this?

Thanks!
 
In .htaccess or your httpd conf file (whichever you use)

Code:
redirect 301 /forums/tags.php http://www.mysite.com/forums/tags/
redirect 301 /forums/tags.php?tag=videos http://www.mysite.com/forums/tags/videos/
etc.
 
Thanks for the input but I forgot to mention that those URLs are just examples... I want to redirect a lot of those and I showed the URL structure looking for a redirection rule that will work for all of these!
 
@Jake Bunce is the wizard...

I use this to wildcard redirect all urls that match the criteria (/forum/blogs/) to a single url. you might be able to adapt on it or at least make it so you only need one rule for every 5 urls?

Code:
RedirectMatch 301 ^/forum/blogs/.*$ https://www.mysite.com/forums/blogs-have-moved.117/
 
There are 3 patterns there.

Add these rules to the top of the .htaccess file in the web root of http://www.mysite.com :

Code:
RewriteEngine On

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)&page=([0-9]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/%2/page-%3? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/%2/? [R=301,L]

RewriteRule ^tags\.php$ /forums/tags/? [R=301,L]
 
@Jake Bunce unfortunately it's not working... for example this link:

www.mysite.com/forums/tags.php?tag=neutralidad

Is still going to the same path and XenForo is displaying the standard error message: "The request page wasn't found".

This is my .htaccess file on the root of my site:

Code:
###########################################################
# mod_rewrite and disable indexes
###########################################################
RewriteEngine on
Options +FollowSymLinks
Options -Indexes

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)&page=([0-9]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/%2/page-%3? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/%2/? [R=301,L]

RewriteRule ^tags\.php$ /forums/tags/? [R=301,L]

###########################################################
# Add 'www.' prefix
###########################################################
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

###########################################################
# Root to forums
###########################################################
RedirectMatch permanent ^/$ http://www.mysite.com/forums
 
My mistake.

Add these rules to the top of the .htaccess file in the /forums directory:

Code:
RewriteEngine On

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)&page=([0-9]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/%2/page-%3? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/%2/? [R=301,L]

RewriteRule ^tags\.php$ /forums/tags/? [R=301,L]
 
Try this:

Code:
RewriteEngine On

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)&page=([0-9]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/${unesc:%2}/page-%3? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/${unesc:%2}/? [R=301,L]

RewriteRule ^tags\.php$ /forums/tags/? [R=301,L]

I haven't tried this before but that's what I found in this guide:

http://stackoverflow.com/questions/18990593/apache-rewriterule-redirection-with-url-encoded
 
Thanks @Jake Bunce but unfortunately it's not working.

:(

Then maybe this syntax:

Code:
RewriteEngine On

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)&page=([0-9]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/%{unesc:%2}/page-%3? [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)tag=([^&]+)($|&)
RewriteRule ^tags\.php$ /forums/tags/%{unesc:%2}/? [R=301,L]

RewriteRule ^tags\.php$ /forums/tags/? [R=301,L]
 
Back
Top Bottom