mod_rewrite 从任何页面重定向到主页
如果有人转到任何文件夹,例如 http://site.com/images/
或 http://site.com/images
到 http,我需要重定向://site.com
。 除非他去文件例如http://site.com/images/index.php
在这种情况下它不会重定向
现在我使用
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]
但我认为它不完美因为例如如果有人出现http://www.site.com 它不起作用。
请记住,由于服务器配置,我需要将 .htaccess 放入每个文件夹中。
I need to redirect if someone goes to any folder e.g. http://site.com/images/
or http://site.com/images
to http://site.com
.
Unless he goes to file e.g. http://site.com/images/index.php
in this case it does not redirect
now i use
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]
but i think its not perfect because e.g. if someone comes on http://www.site.com it does not work.
Keep in mind due to server configuration i need to put .htaccess in every folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您正在寻找的是 -f 标志:
请参阅 http://httpd.apache.org/docs/current/mod/mod_rewrite.html
如果您只是想阻止某人获取文件列表您文件夹中有,您可能需要考虑添加:
如果给定目录中不存在索引页,这将告诉 apache 不要显示目录列表。
请参阅 http://httpd.apache.org/docs/2.2/mod /core.html#options
最后要注意的是,如果您不熟悉 .htaccess 的工作原理,apache 会扫描当前文件夹及其任何父文件夹 - 您应该只添加一个单身的http://site.com 的网络根目录中的 .htaccess 文件。 此处的另一个问题对此进行了介绍。
I believe that what you are looking for is the -f flag:
See http://httpd.apache.org/docs/current/mod/mod_rewrite.html
If you are only looking at stopping someone from getting a list of the files you have in the folder, you may want to consider instead adding:
This will tell apache not to display a directory list if no index page is present in the given directory.
See http://httpd.apache.org/docs/2.2/mod/core.html#options
The last thing to note, if you are not familiar with how .htaccess works, apache scans the current folder and any of its parent folders - you should be okay with only adding a single .htaccess file in your web root for http://site.com. This has been covered in another question here.