简体   繁体   中英

.htaccess - Rewrite query string and redirect to directory

I have some old URL's that I want to fix because of a forum migration.

The old URL's look like: http://www.example.com/forum/topic.asp?TOPIC_ID=666

I want to redirect them to: http://www.example.com/forum/missions/666

My approach is this, but I'm scratching my head, because it doesn't work at all:

RewriteCond %{QUERY_STRING}     ^TOPIC_ID=(.*)$    [NC]
RewriteRule ^/forum$       /forum/missions/%1      [NC,L,R=301]

Assuming there is no .htaccess in `/forum/, you can use this first rule in your root .htaccess:

RewriteCond %{QUERY_STRING} ^TOPIC_ID=([^&]+) [NC]
RewriteRule ^forum/topic\.asp$ /forum/missions/%1? [NC,L,R=302]

If there is a .htaccess in /forum/ , then you can use this first rule in your /forum/.htaccess :

RewriteCond %{QUERY_STRING} ^TOPIC_ID=([^&]+) [NC]
RewriteRule ^topic\.asp$ /forum/missions/%1? [NC,L,R=302]

I'd suggest this, but cannot really try from here :)

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    RewriteRule ^forum/topic.asp\?TOPIC_ID=([0-9]+)$ forum/missions/$1 [L]

</IfModule>

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