简体   繁体   English

.htaccess-重写查询字符串并重定向到目录

[英].htaccess - Rewrite query string and redirect to directory

I have some old URL's that I want to fix because of a forum migration. 由于论坛迁移,我想修复一些旧的URL。

The old URL's look like: http://www.example.com/forum/topic.asp?TOPIC_ID=666 旧网址看起来像: http : //www.example.com/forum/topic.asp?TOPIC_ID=666

I want to redirect them to: http://www.example.com/forum/missions/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]

Assuming there is no .htaccess in `/forum/, you can use this first rule in your root .htaccess: 假设`/ forum /中没有.htaccess,则可以在根.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 : 如果/forum/有一个.htaccess,那么您可以在/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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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