Php 如何使用.htaccess隐藏网页名称后的所有内容

Php 如何使用.htaccess隐藏网页名称后的所有内容,php,.htaccess,url,mod-rewrite,get,Php,.htaccess,Url,Mod Rewrite,Get,当我进入我的站点和浏览其他站点时,我会得到一个参数more:etc.php?p=pagename&id=1 我想隐藏一切后。dk 我试过: RewriteEngine On RewriteRule ^([a-zA-Z0-9]+)$ index.php?p=$1 [L,QSA] RewriteRule ^([a-zA-Z0-9]+)/$ index.php?p=$1 [L,QSA] RewriteRule ^/index.php$ http://www.madsweb.dk/ [R,NC,L]

当我进入我的站点和浏览其他站点时,我会得到一个参数more:etc.php?p=pagename&id=1

我想隐藏一切后。dk

我试过:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?p=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?p=$1 [L,QSA]

RewriteRule ^/index.php$ http://www.madsweb.dk/ [R,NC,L]
但它似乎不起作用

有人能帮我吗

我想隐藏一切后。dk

这是不可能的。mod_rewrite无法消除对每个资源具有唯一URL的需要

(如果你真的做到了,那么它会破坏链接,包括书签和搜索引擎)

重写规则^/index.php$[R,NC,L]

重写则相反。您不会重写用户在地址栏中看到的内容,而是将一个请求重写为另一个请求(如重定向,但在服务器上透明地处理)

这也是你在那里尝试做的事情不可能的原因

如果你喜欢90年代,不在乎可用性,你可以用框架来代替

但撇开玩笑不谈,最好是建立在这条已经很好的规则之上:

重写规则^([a-zA-Z0-9]+)$index.php?p=$1[L,QSA]

并将附加信息(
id
在本例中)输入到模式中。例如:

RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?p=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/([0-9]+)$ index.php?p=$1&id=$2 [L,QSA]
或更一般(但仍然只有一个参数):

Heeej

试试

$pathInfo=explode('/',trim($_SERVER['PATH_INFO'],'/')
$pagina=$pathInfo[0]
$actie=$pathInfo[1];重写规则 ^([a-zA-Z0-9]+)/?$index.php?p=$1[L,QSA]重写规则 ^([a-zA-Z0-9]+)/([0-9]+)$index.php?p=$1&id=$2[L,QSA]

或更一般(但仍然只有一个参数):

列表($pagina,$actie)=分解('/',修剪($_SERVER['PATH\u INFO'],'/')

您也可以尝试:

选项+跟随符号链接发动机打开 重写规则^folder1/(*)$ /链接。 com/folder2/$1[R=301,L]


我认为你不能隐藏URL的那一部分。除非您通过POST或Cookie进行导航并忽略所有URL。
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?p=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([0-9]+)$ index.php?p=$1&$2=$3 [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?p=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([0-9]+)$ index.php?p=$1&$2=$3 [L,QSA]