如何prevent两个环节表现出同样的内容的.htaccess? [英] How to prevent two links show the same content with .htaccess?

查看:114
本文介绍了如何prevent两个环节表现出同样的内容的.htaccess?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的情况:

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

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

If the user accesses the folder (/css/), I want that Apache returns the file. If the user tries to access the file directly, (/css/something.css), I want that he be redirected to the folder.

我怎么能做到这一点没有得到一个循环?我读了很多,但我不能算出它采用两个规则,它总是返回一个循环。注:这是我对堆栈溢出的第一个问题。谢谢你在前进。

How can I do this without getting a loop? I've read a lot but I couldn't figure it out applying two rules, it always returns a loop. Note: this is my first question on Stack Overflow. Thank you in advance.

推荐答案

把这些在您的文档根目录下的htaccess文件:

Put these in your htaccess file in your document root:

# 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]

这篇关于如何prevent两个环节表现出同样的内容的.htaccess?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆