[英]How to replace a specific .html into a trailing slash using HTACCESS
我在.htaccess中有此命令
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
並且此命令在結尾處刪除.html,這看起來還可以,但是如何在結尾處添加呢? 因為如果我嘗試以下代碼:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_URI} !\.(php|html?|jpg|gif)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
.html再次出現。 我想將.html替換為斜杠。 我也只想在1個HTML文件中執行此操作。 所以我的網址目前是這樣。
http://mysamplesite.com/project.html/
您可以使用:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ /$1.html [L]
嘗試以下規則,我假設項目是要在其上加上斜杠的文件。
RewriteEngine On
RewriteRule ^project$ project/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([\w-]+)/?$ $1.html [L]
您可以像這樣使用它:
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+project\.html\s [NC]
RewriteRule ^ http://%{HTTP_HOST}/%{REQUEST_URI}/ [NC,L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.