使用.htaccess,如何使用Square Brackets []重定向URL

时间:2016-09-14 15:05:26

标签: php apache .htaccess redirect

我想重定向此网址:

http://example.com/main2.php?t202id=2483&mnin=pubd&t202kw=[zone]

example.com/newpage.php

但仅当访问者在网址末尾点击了[zone]的网址时,如果他访问了这样的网址:

example.com/main2.php?t202id=2483&mnin=pubd&t202kw=XXXXXXXX

他不能被重定向。

2 个答案:

答案 0 :(得分:1)

如果你真的想使用htaccess而不是php:

RewriteEngine On
RewriteCond %{QUERY_STRING} ".*t202kw=\[zone\].*"
RewriteRule ^  http://example.com/newpage.php  [R=301,L,QSD]

答案 1 :(得分:0)

这可能比使用htaccess更容易在PHP脚本中完成。在main2.php脚本顶部/附近有类似的东西:

if ($_GET['t202kw'] == "[zone]") {
    header("Location: /newpage.php");
    http_response_code(301); // this is the HTTP code for "Moved Permanently" -- change to 302 if this redirect is only temporary
    exit();
}