我有这个巨大的问题,我不知道如何解决.我有一个重定向到网址的脚本.
到目前为止,我有:
//do some mysql
$geo_included = true; //trying to fix infinite redirect loop.
if($geo_included === true){
header('Location: '.$url["url"]); //this is causing the issue with redirect loop
}
Run Code Online (Sandbox Code Playgroud)
例如,$ url ["url"]是:www.google.com
但是,当我转到该PHP文件时,它将重定向到:
www.sitename.com/www.google.com
Run Code Online (Sandbox Code Playgroud)
并说有一个无限的重定向循环.注意:上面的标题位置脚本不在while/for/foreach循环中.
这是/目录的.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?group=$1 [L]
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
您需要在scheme中包含完全限定的域名,否则它将被解释为在当前域中:
header('Location: google.com'); // Redirects to http://cursite.com/www.google.com
header('Location: http://google.com'); // Redirects as expected
Run Code Online (Sandbox Code Playgroud)
如果您不确定您的URL是否包含方案,请检查结果parse_url.
$url_scheme = parse_url($url, PHP_URL_SCHEME);
// www.google.com -> NULL
// http://google.com -> string(4) "http"
// ftp://site.com -> string(3) "ftp"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2499 次 |
| 最近记录: |