我的目录中有以下 .htaccess 文件:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.mysite.com/launch [R,L]
DirectoryIndex index.html
基本上,这会强制 mysite.com/launch 下面的所有页面使用 SSL 版本 https://www.mysite.com/launch/index.html .
但是,对于/launch 下的单个子目录,我需要能够允许访问而无需重定向用户。
例如,如果他们导航到 www.mysite.com/launch/files/photos,那么他们应该能够访问/photos 目录中的各个文件。
我是否要在/photos 目录中使用另一个 .htaccess 文件,还是要修改/launch 目录中现有的 .htaccess 文件?
最佳答案
我用过类似的东西。
RewriteRule ^(?!intranet/|cv/)(.+)$ somedirname/$1 [L]
RewriteRUle ^$ somedirname/ [L]
因此,当调用 mysite.com/intranet 时,它会进入文件夹 Intranet 或者当调用 mysite.com/cv 时,它会进入 cv 文件夹
但在这种情况下,当没有子目录被调用时,它会强制进入“somedirname”
当然你可以将最后一个rewriterule改为RewriteRule ^(.*)$
为https://www.mysite.com/launch [R,L]
将另一个重写规则放在上面以检查它是否是他们可以访问的目录
所以你最终会得到这样的结果:
RewriteCond %{HTTPS} !=on
RewriteRule ^(?!subdir1/|subdir2/)(.+)$ launch/$1 [L]
RewriteRule ^(.*)$ https://www.mysite.com/launch [R,L]
DirectoryIndex index.html
现在
www.mysite.com/subdir1
和
www.mysite.com/subdir2
可以在浏览器中打开
关于.htaccess - 删除子目录中的.htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2378216/