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

时间:2022-01-23 10:50:39

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?

我有一个类似于example.com/index.php?p=test的URL,以便PHP使用$ _GET ['p']加载测试变量。该URL已经可以简化为example.com?p=test;但是,我希望在我的.htaccess到site.com/test中简化这一点。我该怎么做呢?

1 个解决方案

#1


13  

Place the following in your .htaccess file:

将以下内容放在.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]

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

然后,您可以访问example.com/whatever中的任何内容,如下所示:

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

#1


13  

Place the following in your .htaccess file:

将以下内容放在.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]

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

然后,您可以访问example.com/whatever中的任何内容,如下所示:

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