.htaccess RewriteRule redirect URL containing specific parameters

I have seen several questions regarding similar requests, however I am not trying to redirect to a custom url. I just want to use shared URLs that have been linked and redirected to the landing page.

For example, I want to catch a specific URL as shown below, but only this URL:

http://example.com/forum/viewtopic.php?f=12&t=345

... and redirect it to:

http://example.com/landing-page.html

I have some links that no longer exist, so I will add 4 or 5 redirects to more useful pages since they are currently clicking 404.

Thanks in advance!

+4
source share
1 answer

Add this to your htaccess file in your document root:

RewriteCond %{QUERY_STRING} ^f=12&t=345$ RewriteRule ^forum/viewtopic.php$ /landing-page.html [R=301] 

Essentially, you want to match the query string in this RewriteCond and the URI in the RewriteRule .

+1
source

All Articles