简体   繁体   中英

Rewrite url with querystring

I am creating a new website for a company and I am creating new url's for all pages. For example a forum topic used to be /cont/forum/showTopic.php?id=5 and now it is /forum/5 .

This site has a lot of backlinks from all over the web and I would like to make sure that these links still got to the correct page. I have already tried several things with .htaccess , but I am stuck with getting the value of the querystring.

If someone could help me with this example. Once I know how it is done, I can do the rest.

To redirect /cont/forum/showTopic.php?id=5 to /forum/5

Place this rule in root .htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+cont/forum/showTopic\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /forum/%1? [R=302,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM