重写规则隐藏文件夹,不会没有结尾的斜线的工作权利 [英] Rewrite rule to hide folder, doesn't work right without trailing slash

查看:225
本文介绍了重写规则隐藏文件夹,不会没有结尾的斜线的工作权利的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的Apache的mod_rewrite问题。我需要隐藏来自用户的子目录,但重定向每一个请求到该子目录。我发现了几个计算器相当类似的问题,但没有真正适合,所以我决定发布一个新的问题。

i have a strange apache mod_rewrite problem. I need to hide a sub-directory from the user, but redirect every request to that sub-directory. I found several quite similar issues on stackoverflow, but nothing really fits, so i decided to post a new question.

我的.htaccess看起来是这样的:

My .htaccess looks like this:


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)?$ foo/$1 [QSA,L]

文档根目录仅包含以下文件夹/文件:

The document-root only contains the following folder/files:

/foo/bar/index.html

我现在期待example.com/bar和example.com/bar/将只显示我的index.html的内容。

I would now expect that example.com/bar and example.com/bar/ would just show me the contents of index.html.

相反example.com/bar/告诉我含量预期,但example.com/bar重定向我一个301 example.com/bar/foo/~~V一个然后显示的内容。我真的不明白为什么在这种情况下,301重定向。

Instead example.com/bar/ show me the content as expected but example.com/bar redirects me with a 301 to example.com/bar/foo/ an then shows the contents. I really don't get why there is a 301 redirect in this case.

当我把这个东西。


RewriteCond %{REQUEST_URI} !^[^.]*/$
RewriteCond %{REQUEST_URI} !^[^.]*\.html$
RewriteCond %{REQUEST_URI} !^[^.]*\.php$
RewriteRule ^(.*)$ $1/ [QSA,L]

这是该规则似乎工作之上,但是这将需要我列出每一个使用过的文件扩展名...

on top of that rule it seems to work, but that would require me to list every used file extension...

还有没有其他的办法可以省略重定向,文件夹栏不应该由外部用户看到。

Is there any other way i can omit the redirect, the folder "bar" should never be seen by an outside user.

在此先感谢!

推荐答案

优于从不迟到......

Better late than never...

得到它用一个简单的重写规则而追加/到没有对每个URL的工作。

Got it working with a simple RewriteRule which append a / to every url that doesn't have on.

# only directories
RewriteCond %{REQUEST_FILENAME} !-f
# exclude there directories
RewriteCond %{REQUEST_URI} !^/excluded-dirs
# exclude these extensions
RewriteCond %{REQUEST_URI} !\.excluded-extension$
# exclude request that already have a /
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [R=301,L]

这篇关于重写规则隐藏文件夹,不会没有结尾的斜线的工作权利的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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