gpt4 book ai didi

php - 使用查询字符串隐藏 url 的 .php 扩展名

转载 作者:搜寻专家 更新时间:2023-10-31 21:27:08 25 4
gpt4 key购买 nike

我正在使用 .htaccess 文件进行 url 重写。我用 .php 扩展名编写了所有页面并隐藏它们我正在使用此代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]`

但是当我将“www.example.com/abc.php”写入“www.example.com/abc”时,这会隐藏。我希望它们像我单击链接时一样自动更改

<a href="example.php">example</a>

然后页面链接应该像“www.example.com/example”而不是“www.example.com/example.php”一样打开

另外,如何从所有页面隐藏“?var="hello",但变量应该发送到该页面是可能的吗?。

更新

例如我在这里使用这个

<?php 
if(isset($_GET['hi'])){
echo $_GET['hi'];
}
?>
<a href="a.php?hi=sdsdsd">a</a><br>
<a href="b.php">b</a><br>
<a href="c.php">c</a><br>
<a href="d.php">d</a><br>

我希望无论页面是什么都应该在没有扩展名的情况下访问,查询字符串应该隐藏但必须访问。

最佳答案

使用这个 .htaccess:

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

关于php - 使用查询字符串隐藏 url 的 .php 扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34429330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com