0
A
回答
0
您重定向代码:
header('Location: /index.php/Register/',true,302);
exit;
为了访问/寄存器/值,使用:
$_SERVER['PATH_INFO']
0
在使用header命令执行重定向之后,您必须记得编写代码来处理该URL。
/index.php/Register将尝试加载内部“/index.php/”文件夹中的“注册”的文件...... 404错误
所以,你需要使用Apache modrewrite重定向这些“虚拟文件夹“转换为可处理它的集中式脚本。
像这样的的.htaccess:
RewriteEngine on
RewriteRule ^index.php/(.*)$ index.php
然后,在你的index.php,你将把进来的URL来检测该文件,做任何你想用它。
我通常使用catch-all(将所有内容重定向到/index.php),然后中断URL并处理它,这样我就可以拥有任意数量的虚拟文件夹/文件。下面是我自己的功能,以处理任何传入的请求:
function extractUri($uri="") {
if ($uri == "") $uri = isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != "" ? $_SERVER['REQUEST_URI'] : "";
if ($uri != "") {
# removes query from request
if ($uri[0] != "/") $uri = "/".$uri; # ALWAYS START WITH/
$uri = explode("?",$uri);
$uri = str_replace("..",".",array_shift($uri)); # little exploit remover
$uri = explode("/",str_replace("//","/",$uri));
} else
$uri = array("/");
$context = array();
foreach ($uri as $part)
array_push($context,preg_replace("/(\.){2,}/","\.",$part)); # prevents ..
$action = array_pop($context); # file (with extension)
$original_action = $action; # preserve the original file with extension (I work w/o them)
$ext = "";
if ($action == "") $action = 'index'; # so if you are accessing folder/, then you probably want the index
else if (strpos($action,".")!==false) { # remove extension
$action = explode(".",$action);
$ext = array_pop($action);
$action = implode(".",$action);
$action = removeSimbols($action,true,false); # makes sure it is a valid filename, this function removes any weird character
}
return array($context,$action,$original_action,$ext); # returns the folder structure (array), the page/action, the page/action with extension, and said extension (lots of repetition to speed up later)
}
所以extractUri( “/ index.php文件/注册”)将返回:
Array ([0] => "/", [1] => "index.php"), "Register", "Register", ""
相关问题
- 1. URL重写不重定向
- 2. URL重写和重定向
- 3. URL重写重定向
- 4. htacces URL重写重定向
- 5. IIS URL重写重定向
- 6. URL重写和301重定向...重定向到原始URL
- 7. Url映射,Url重定向/重写
- 8. URL重写和URL重定向
- 9. PHP URL重定向
- 10. php ---- url重定向
- 11. PHP重定向URL
- 12. PHP重定向URL
- 13. PHP重定向URL
- 14. 的.htaccess重写重定向的URL
- 15. 重写重定向的URL与mod_rewrite的
- 16. 重定向或重写URL到新的
- 17. Nginx的重写URL未能重定向
- 18. .htaccess带URL重写的SSL重定向
- 19. Django的内部重定向/ URL重写
- 20. Apache重写中的URL重定向
- 21. nginx的URL重写(无重定向)
- 22. 无重定向的URL重写
- 23. URL重写/重定向/使用的.htaccess
- 24. 重定向到重写的URL问题
- 25. 重定向后的URL重写
- 26. 的.htaccess URL重写和重定向301
- 27. 的.htaccess重写URL启动/重定向
- 28. 301重定向到URL重写.htaccess的
- 29. mod_rewrite的 - 力重定向到重写URL
- 30. 重定向到一个重写的URL
的可能重复[访问GET变量与PHP +。 htaccess](http://stackoverflow.com/questions/3375680/access-get-variables-with-php-htaccess) – Machavity 2014-10-17 20:17:12
它看起来像你只需要改变按钮链接到的网址。 – jeroen 2014-10-17 20:18:07
index.php /注册/重定向不工作,相信我,我已经尝试过了。 – Yildirim 2014-10-17 20:20:22