Php Mod_Rewrite不重写URL

Php Mod_Rewrite不重写URL,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,我有以下url结构: /page.php?file=about /page.php?file=contact 等 .htaccess文件具有以下代码: RewriteEngine On RewriteRule ^([^/]*)\.html$ /page.php?file=$1 [L] 根本不尝试重写URL。我在找像/about.html、/contact.html这样的东西 是.htaccess代码还是服务器上的某种设置?您可以使用: RewriteEngine On RewriteCo

我有以下url结构:

  • /page.php?file=about
  • /page.php?file=contact
.htaccess文件具有以下代码:

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /page.php?file=$1 [L]
根本不尝试重写URL。我在找像/about.html、/contact.html这样的东西

是.htaccess代码还是服务器上的某种设置?

您可以使用:

RewriteEngine On

RewriteCond %{THE_REQUEST} /page\.php\?file=([^\s&]+) [NC]
RewriteRule ^ /%1.html? [R=302,L,NE]

RewriteRule ^([^/]+)\.html$ page.php?file=$1 [L,QSA,NC]

只是一些额外的信息,我以前在同一台服务器上安装了Wordpress,它可以很好地重写URL,所以我很确定这是我做错了!您在浏览器中输入的URL是什么?WP还在使用吗?Wordpress现在关闭了,这只是我制作的一个很小的网站,并尝试使用mega basic模板系统。我输入的URL是site.com/page.php?file=about,它重写了URL,但实际上试图查找about.html,例如,404显然是因为没有这样的文件。一定还是有问题,因为它不是那样工作的抱歉,我不确定需要什么信息。如果我删除了.htaccess,那么站点将按照预期的方式呈现包含页面内容的页面模板(page.php)。我只是想让该URL看起来更像/about.html,而不是page.php?file=about未找到此服务器上未找到请求的URL/about.html。您的设置不正确
public\u html
dir应该是网站根目录,但这里有一个子目录。我相信
page.php
也在
public\uhtml
中,对吗?如果您控制Apache,那么最好将
公开\u html
您的
DocumentRoot