2014-03-06 27 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] 
相關問題