如何防止两个环节显示出与.htaccess中的相同内容?(How to prevent two li

2019-10-16 22:41发布

我有这样的情况:

  • / CSS / < - 一个夹
  • /css/something.css < - 一个文件

如果用户访问的文件夹(/ CSS /),我想阿帕奇返回文件。 如果用户试图访问直接的文件,(/css/something.css),我想,他被重定向到该文件夹​​。

我怎样才能做到这一点没有得到一个循环? 我已经读了很多,但我无法弄清楚应用两个规则,它总是返回一个循环。 注:这是我的堆栈溢出的第一个问题。 先感谢您。

Answer 1:

你的文档根把这些在你的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]


文章来源: How to prevent two links show the same content with .htaccess?