Apache 使用mod_重写使搜索看起来像html页面

Apache 使用mod_重写使搜索看起来像html页面,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我希望我的URL当前看起来像 太像这样了, 下面的代码使URL看起来像这样 如何让它在结尾添加.html?我试过几次,但都没能成功 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?([^/]+)/(.*) search.php?q=$1 [L,QSA] 只需将html添加到模式中: RewriteEngine On Rewrite

我希望我的URL当前看起来像

太像这样了,

下面的代码使URL看起来像这样

如何让它在结尾添加.html?我试过几次,但都没能成功

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/(.*) search.php?q=$1 [L,QSA]

只需将html添加到模式中:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)\.html$ search.php?q=$1 [L,QSA]
你差点就成功了:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+).html$ search.php?q=$1 [L,QSA]
([^.]+)
是第一组,表示任何不是点的东西
.html
是与所需扩展名匹配的剩余部分

由于您在
.htaccess
上使用此选项,因此不需要
/?