Php 如何在获取URL时重定向页面

Php 如何在获取URL时重定向页面,php,.htaccess,url,Php,.htaccess,Url,我有一个像index.php?controller=a&action=b这样的页面,但是在这个页面controller=a上我什么都没做,如果我只是访问一个空白页面的话。我需要从controller=a重定向到原始页面controller=a&action=b?如果只检查页面url并重定向 if(isset($_GET['controller']) && $_GET['controller'] == "a"){ header("location: index.php");

我有一个像index.php?controller=a&action=b这样的页面,但是在这个页面controller=a上我什么都没做,如果我只是访问一个空白页面的话。我需要从controller=a重定向到原始页面controller=a&action=b?

如果只检查页面url并重定向

if(isset($_GET['controller']) && $_GET['controller'] == "a"){
    header("location: index.php");
}

你的问题令人困惑。。。我会尽我最大的努力帮助你,这里有一个网站可以帮助你:

另一个可能有助于.htaccess的建议如下:

RewriteRule ^controller/([0-9A-z_-]+)\/action/([0-9A-z_-]+)\/$ index.php?controller=$1&action=$2 [QSA,L,NC]

通过这种方式,您可以使用链接www.domain.com/controller/a/action/b/访问index.php?controller=a&action=b

我得到了一个警告:无法修改标题信息-标题已经由…在更改标题之前,您不能输出任何html,因此此函数应该位于php文件的顶部…哦,也许这就是问题所在,在检查url之前,我有html代码,因为我对我的内容使用include我不使用htaccess,我不需要它,我的问题示例:如果我访问url index.php?controller=a,然后重定向到index.php?controller=a&action=b,因为那里没有内容,然后我也为index.php做了这件事,因为那里也没有什么。你需要更清楚这里的目标。。。在被重定向之前,是否要检查是否存在文件??如果文件_存在'index.php'{headerlocation:index.php;}