我有一个索引文件在www /和apache config下设置DirectoryIndex到index.html
如果我使用此链接
example.com/
一切正常,因为html本身有元标记不使用缓存 但如果我使用
example.com (Which in url bar will redirect to example.com/)
//Note: In chrome, the initiator for this also change to example.com
始终从缓存中提取索引
第二种方式是正常的最终用户输入地址的方式。你能解释一下发生了什么吗?
答案 0 :(得分:1)
example.com/
的处理方式与example.com
不同。斜杠表示URL是文件夹而不是文档。添加额外的斜杠(例如example.com///
)也将构成这方面的独立缓存。
我建议强制使用单个尾部斜杠,可以使用以下.htaccess
完成:
RewriteEngine On
# Assuming you're running at domain root. Change to working directory if needed.
RewriteBase /
# www check
# If you're running in a subdirectory, then you'll need to add that in
# to the redirected url (http://www.example.com/subdirectory/$1
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# Trailing slash check
# Don't fix direct file links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
# Finally, forward everything to your front-controller (index.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [QSA,L]
有关此内容的更多信息,请访问 here 。
希望这有帮助! :)