.htaccess-重写查询字符串并重定向到目录
问题描述:
由于论坛迁移,我有一些旧URL要修复。
I have some old URL's that I want to fix because of a forum migration.
旧URL看起来像:
http://www.example.com/forum/topic.asp?TOPIC_ID=666
我要将其重定向到:
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]
答
假设`/ forum /中没有.htaccess,则可以在根.htaccess中使用此第一条规则:
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]
如果 / forum /
,那么您可以在 /forum/.htaccess
中使用此第一条规则:
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]