的.htaccess更换(重写)在PHP网址$ _GET变量重写、变量、网址、htaccess

2023-09-02 00:27:48 作者:绾鸢丶

我有一个网址,这将是这样的 example.com/index.php?p=test ,使得PHP将使用加载测试变量 $ _ GET ['P'] 。该网址已经可以简化为 example.com?p=test ;不过,我希望在我的的.htaccess 简化为 site.com/test 。我将如何去这样做?

I have a URL that will be something like example.com/index.php?p=test so that the PHP will load the test variable using $_GET['p']. The URL can already be simplified to example.com?p=test; however, I wish to simplify this in my .htaccess to site.com/test. How would i go about doing this?

推荐答案

将在的.htaccess 文件如下:

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 这样的:

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