.htaccess-重写查询字符串并重定向到目录 [英] .htaccess - Rewrite query string and redirect to directory

查看:70
本文介绍了.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]

这篇关于.htaccess-重写查询字符串并重定向到目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆