2014-03-06 26 views
0

我想我的网址,目前的样子,使搜索看起来像HTML页面的mod_rewrite

http://www.mydomain.com/search.php?q=blue+widgets

过这个样子,

http://www.mydomain.com/blue+widgets.html

下面的代码,使URL格式像这样,

http://www.mydomain.com/blue+widgets/

如何才能在最后添加.html?我尝试了几件事情,但无法使其发挥作用。

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

回答

1

你几乎拥有了:

Options +FollowSymLinks -MultiViews 

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

([^.]+)是弗里斯特团,是指任何不点
.html是留下来匹配你想要的扩展名

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

0

只包含HTML文件添加到模式:

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