如何在PHP中写一个干净的网址?

时间:2013-10-02 09:06:06

标签: php mysql .htaccess

如何从http://domain.com/details.php?users=53#People写一个干净的网址到http://domain.com/53#people/ 锻炼我需要帮助研究员

1 个答案:

答案 0 :(得分:3)

您真正要求的是对details.php的请求被路由到index.php。

因此,您需要在index.php中使用一些代码来了解此请求的详细信息。

您可以在 .htaccess 文件

中使用此功能
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

index.php 中,您可以提取实际请求并对其进行操作。

$request = substr($_SERVER['PHP_SELF'], strlen('/index.php'));