.htaccess Force Trailing Slash Rewrite

时间:2015-04-01 15:27:39

标签: apache .htaccess mod-rewrite trailing-slash

道歉,但我对URL Rewrites相当新。我已经设法让传统意义上的重写工作,但不能强迫它有一个尾随斜杠。

以下是代码:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ /$1.html [L,QSA]

1 个答案:

答案 0 :(得分:0)

您可以尝试:

RewriteEngine On
RewriteBase /

# add a trailing slash for non-files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)/?$ $1.html [L]