.htaccess重写规则获胜';不起作用


.htaccess RewriteRule won't work!

我在菜单系统中使用php开关[_get]创建url.com/?p=page,我想把它改成url.com/page.html。但我不能让它工作,也许你们中的一些人知道正确的设置。

我目前正在使用这个作为.htaccess:

RewriteEngine On
RewriteBase /
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www'.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^start(.*)'.html$ ?p=start$

谢谢!

更新:

我尝试了$1,但当我希望它是/start.html 时,url仍然是:?p=start

上一条规则中似乎缺少$1

RewriteRule ^start(.*)'.html$ ?p=start$1
                                     ^^^^

编辑获取新信息后,请尝试:

RewriteCond %{QUERY_STRING} p=([a-z0-9]+) [NC]
RewriteRule . /%1.html [L]

这将从查询字符串中捕获p=参数,并使用它重写为page.html

尝试

RewriteRule ^start(.*)'.html$ ?p=start$1 [L]

请参见末尾的一(1)。

htaccess则相反。

它使/start.html代理到?p=start,但是,您仍然需要使链接本身成为/start.html的目标。

因此,将所有<a href="?p=start">更改为<a href="/start.html">

您需要

RewriteCond %{QUERY_STRING} ^p=(.+)$ [NC]
RewriteRule ^$ /%1.html? [R=301,L]

R=301是在浏览器中更改url,但是你仍然需要更新网站上的所有链接:

<a href="?p=start"><a href="/start.html">

编辑:尝试更新的(在html后面有一个?)