2016-12-23 102 views
1

我正在使用WordPress。我需要添加一個自定義重寫小節。我想爲單個頁面提供兩個網址。重寫規則以添加.html後綴

例如:

www.test.com/abc < ---目前,這是實現&工作的罰款。

www.test.com/abc.html < ---需要在背面添加.html。

我想允許訪問與.html擴展名相同的頁面。

我該怎麼做?

回答

1

我通過評論來解釋。

RewriteEngine on 
RewriteBase/

# Make sure it's not an actual file or directory 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# Make sure the hostname is www.test.com 
RewriteCond %{HTTP_HOST} ^www\.test\.com 

# If the request matches "abc.html", rewrite to abc 
RewriteRule ^abc\.html$ abc [L,QSA] 

# If you need to make this a generic rule, try this instead: 
#RewriteRule ^(.*)\.html$ $1 [L,QSA] 

隨意丟棄L標誌,如果不是最後一個重寫規則。有關詳細信息,請參閱RewriteRule Flags

您可以test it online

+0

非常感謝你:)它的工作。現在我想保持動態值,而不是「ABC」於是(\ w +)應該工作的權利? – Amar

+0

這就是'RewriteRule ^(。*)\。html $ $ 1 [L,QSA]' – sepehr