简体   繁体   English

页面的永久重定向取决于参数

[英]Permanent redirect of page dependent on parameters

I want to redircet www.mysite.com/abc/mypage.php?id=123 to www.mysite.com/newpage.htm 我想重新调配www.mysite.com/abc/mypage.php?id=123到www.mysite.com/newpage.htm

I've tried this in my .htaccess file but it doesn't work. 我已经在我的.htaccess文件中尝试过此操作,但是它不起作用。 (I just get a 404) (我刚得到一个404)

RedirectPermanent /abc/mypage\.php\?id=123 /newpage.htm

What is the correct syntax? 正确的语法是什么?

No you cannot match QUERY_STRING using Redirect directive. 不,您无法使用Redirect指令匹配QUERY_STRING。 You can use mod_rewrite instead: 您可以改用mod_rewrite

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+abc/mypage\.php\?id=123[&s] [NC]
RewriteRule ^ /newpage.htm? [R=302,L]

Try this: 尝试这个:

# do this once per htaccess
RewriteEngine on

RewriteCond %{QUERY_STRING} ^id=123$
# to redirect permanently
RewriteRule ^/?abc/mypage\.php$ /newpage.htm [R=301,L]

Remember that the [R=302] flag is used to redirect temporarily. 请记住, [R=302]标志用于临时重定向。

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

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