Last active
August 29, 2015 14:02
-
-
Save Kaiyuan/2a365ed2ef8002882b49 to your computer and use it in GitHub Desktop.
PHP 重写 URL 后获取地址中的参数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
# RewriteBase 是文件目录 | |
RewriteRule ^index\.php$ - [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
# RewriteRule 是映射到的实际文件 | |
RewriteRule . /index.php [L] | |
</IfModule> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$request_url = $_SERVER['REQUEST_URI']; //获取全 URL | |
// $request_url = substr(strrchr($request_url, "/"), 1); //直接获得最后一个斜杠后的内容 | |
$get_self = $_SERVER['PHP_SELF']; //获取文件路径 | |
$get_self = substr($request_url, 0, strrpos($get_self, "/")); //获取当前目录 | |
$request_url = substr($request_url, strlen($get_self)+1); //截取页面后面参数 | |
$request_url = explode("/", $request_url); //转换获取的内容为数组 | |
$donateName = urldecode($request_url[0]); // 转换 URL 码 | |
$fn_json = json_encode($request_url); //输出 json | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment