且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

.htaccess 替换(重写)PHP URL 中的 $_GET 变量

更新时间:2023-02-23 10:00:43

将以下内容放入您的 .htaccess 文件中:

Place the following in your .htaccess file:

RewriteEngine on

# The two lines below allow access to existing files on your server, bypassing
# the rewrite

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule (.*) index.php?p=$1 [QSA]

然后您可以从 example.com/whatever 访问 whatever,如下所示:

You can then access whatever from example.com/whatever like the following:

$value = $_GET['p']; // "whatever"