.htaccess replace (rewrite) $_GET variables in PHP URL(.htaccess 替换(重写)PHP URL 中的 $_GET 变量)
问题描述
我有一个类似于 example.com/index.php?p=test
的 URL,以便 PHP 将使用 $_GET['p'] 加载测试变量代码>.URL 已经可以简化为
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
文件中:
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"
这篇关于.htaccess 替换(重写)PHP URL 中的 $_GET 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.htaccess 替换(重写)PHP URL 中的 $_GET 变量


基础教程推荐
- Web 服务器如何处理请求? 2021-01-01
- php中的foreach复选框POST 2021-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的PDF导出 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 将变量从树枝传递给 js 2022-01-01