我有这个案例:
- /css/<-- 文件夹
- /css/something.css <-- 一个文件
如果用户访问文件夹 (/css/),我希望 Apache 返回该文件。如果用户试图直接访问文件 (/css/something.css),我希望他被重定向到该文件夹。
如何在没有循环的情况下执行此操作?我读了很多书,但我无法弄清楚应用两个规则,它总是返回一个循环。注意:这是我在 Stack Overflow 上的第一个问题。提前谢谢你。
最佳答案
将这些放在文档根目录中的 htaccess 文件中:
# internal rewrite to serve the file
RewriteRule ^css/$ /css/something.css [L]
# check if the actual request was for the file, then redirect
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /css/something.css
RewriteRule ^css/something.css$ /css/ [R=301,L]
关于apache - 如何防止两个链接显示与.htaccess 相同的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11352727/