【发布时间】:2015-02-22 23:05:37
【问题描述】:
我是设置 .htaccess 文件的新手,非常感谢您在这个问题上的帮助。
我无法在我网站的所有 URL 中添加尾随 /。我已经尝试了 StackOverflow 和这篇文章的大部分答案,但它对我不起作用,要么样式损坏,要么没有添加 /,要么在尝试这些解决方案时没有添加 /。
可能规则有冲突?
这是我的.htaccess 现在的样子:
# do not allow anyone else to read your .htaccess file
<Files .htaccess>
deny from all
</Files>
# forbid viewing of directories
Options All -Indexes
# hide this list of files from being seen when listing a directory
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
# disable the server signature- helps with preformance
ServerSignature Off
RewriteEngine On
RewriteBase /
# specific rule to show 1 URL but other URL is active
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^([^/]+) $1.html [L]
# hide /index
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
# add trailing /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !http://example.com
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]
我想在除 http://example.com 之外的所有 URL 中添加尾随 /(我正在使用默认的 /index)。
我该如何解决这个问题?
【问题讨论】:
标签: regex apache .htaccess mod-rewrite url-rewriting