我怎样才能让-f标志适用于目录以斜线? [英] How can I make the -f flag apply to directories with a trailing slash?

查看:87
本文介绍了我怎样才能让-f标志适用于目录以斜线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个的.htaccess 文件与一个相当复杂的规则集。

一种基本的重写规则是这样的第一行:

如果请求的文件是否存在身体,就不会有重写,停止处理规则。

 的RewriteCond%{} REQUEST_FILENAME -f [OR]
的RewriteCond%{} REQUEST_FILENAME -d
重写规则。 -  [L]
 

这工作得很好但有一个例外:当我访问一个目录下有一个斜线

  www.example.com/directory/
 

目录将不被认定为existant,而

  www.example.com/directory
 

意志。

我能做些什么来让Apache认识到现有的目录以斜线呢?

背景信息,我已经的添加的斜线,以取得无一(每一个请求同时满足 /目录 /目录/ 的要求。

解决方案

 的RewriteCond%{} REQUEST_FILENAME -d
 

在-d代表目录。另外,根据<一href="http://stackoverflow.com/questions/286004/hidden-features-of-mod-rewrite">http://stackoverflow.com/questions/286004/hidden-features-of-mod-rewrite ,在[L]指令不能在.htacess文件的工作,只是如果你把它放在你的apache的conf文件。

此外,如果你只是刚开始时:

  RewriteEngine叙述上
#不重写它实际存在的文件或目录
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
 

您可以避免重写任何现有的文件或目录。您现有的规则说:如果这是一个真实的文件,继续前进,而雷说:如果它不是一个真正的文件,它不是一个真正的目录,继续前进。

I am building a .htaccess file with a fairly complex ruleset.

One of the basic rewriting rules is this first line:

If a requested file exists physically, no rewriting, stop processing rules.

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]

this works well with one exception: When I access a directory with a trailing slash

www.example.com/directory/

directory will not be recognized as existant, whereas

www.example.com/directory

will.

What can I do to make Apache recognize existing directories with a trailing slash as well?

Background info, I am already adding trailing slash to every request made without one (to cater for both /directory and /directory/ requests.

解决方案

RewriteCond %{REQUEST_FILENAME} -d

The -d stands for directory. Also, according to http://stackoverflow.com/questions/286004/hidden-features-of-mod-rewrite , the [L] directive doesn't work in .htacess files, just if you put it in your apache conf files.

Also if you simply start off with:

RewriteEngine on
# Dont rewrite files or directories which actually exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

You can avoid rewriting any existing files or directories. Your existing rules says "If this is a real file, keep going" whereas mine says "If its not a real file and its not a real directory, keep going."

这篇关于我怎样才能让-f标志适用于目录以斜线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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