PHP/htaccess通过GET重定向

PHP/htaccess通过GET重定向,php,html,apache,.htaccess,redirect,Php,Html,Apache,.htaccess,Redirect,我想: sub.domain.com加载index.php sub.domain.com?s=custom加载/custom/index.php 我现在正在这样做: 在.htaccess中: RewriteRule ^(custom)/?$ index.php?subject=$1 在index.php中,我有: if($_GET['s'] == 'custom') { header( 'Location: http://sub.domain.com/custom/index.php

我想:

  • sub.domain.com
    加载
    index.php
  • sub.domain.com?s=custom
    加载
    /custom/index.php
我现在正在这样做:

在.htaccess中:

RewriteRule ^(custom)/?$ index.php?subject=$1
index.php
中,我有:

if($_GET['s'] == 'custom') {
   header( 'Location: http://sub.domain.com/custom/index.php' ) ;
}
。。。但是是否可以根据GET变量通过htaccess本身进行重定向

谢谢

您可能想使用“重定向匹配”


也许您需要使用regex abit

是的,您可以使用RewriteCond检查查询字符串

RewriteCond %{QUERY_STRING} s=custom
RewriteRule ^(.*?)$ custom/index.php [L]
这样,它将所有具有现有“自定义”get参数的请求重定向到index.php,并且可以扩展:)


想法:

不应该是
s=(.*)
而不是
custom=(.*)
?谢谢。另外,它当前会将任何查询字符串重定向到/custom,如果我想单独重定向该怎么办?也可能会这样做:
RewriteRule s=custom custom/index.php[L]
RewriteCond %{QUERY_STRING} s=custom
RewriteRule ^(.*?)$ custom/index.php [L]