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