.htaccess RewriteRule to redirect url's containing specific parameters

荒凉一梦 提交于 2019-12-10 17:36:57

问题


I've seen several questions regarding similar requests, however, I'm not trying to redirect to a custom crafted URL. I just want to take common URLs that have been linked to and redirect them to a landing page.

For example, I want to catch a specific URL like the following, 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 a few links which no longer exist, so I'll be adding 4 or 5 redirects to more useful pages since they're currently hitting 404's.

Thanks in advance!


回答1:


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.



来源:https://stackoverflow.com/questions/11604444/htaccess-rewriterule-to-redirect-urls-containing-specific-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!