cod*_*nja 2 php apache .htaccess redirect
我需要重定向到index.php请求的任何目录.
所以我需要:
http://www.site.com/folder/files/hello.php
Run Code Online (Sandbox Code Playgroud)
重定向到:
http://www.site.com/folder/files/index.php
Run Code Online (Sandbox Code Playgroud)
对于任何子文件夹也是如此:
http://www.site.com/folder/files/pages/other/hello.php
Run Code Online (Sandbox Code Playgroud)
重定向到:
http://www.site.com/folder/files/pages/other/index.php
Run Code Online (Sandbox Code Playgroud)
构造一个URI,该URI由当前方案(http/ httpsetc),主机名和当前文件的路径组成,并发出Location头.
$url = sprintf('%s://%s%s/index.php',
$_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https',
$_SERVER['SERVER_NAME'], rtrim(dirname($_SERVER['PHP_SELF']), '/'))
header("Location: $url");
exit;
Run Code Online (Sandbox Code Playgroud)
这是因为位置标头URI应该是完整且绝对的.从技术上讲,不允许使用相对URI,但是有一个草案规范设置可以更改它.
只需发出一个相对的Location头,因为它最有可能工作.
header('Location: index.php');
exit;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4695 次 |
| 最近记录: |