开发者

.htaccess replace (rewrite) $_GET variables in PHP URL

开发者 https://www.devze.com 2023-03-14 21:23 出处:网络
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=

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?


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]

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

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

精彩评论

暂无评论...
验证码 换一张
取 消