Mod 重写目录检查
我遇到的情况是,我有多个客户,我希望每个客户都能够通过 mydomain.com/clientname 访问他们的网站。为了使事情井井有条,我将客户站点的实际文件存储在 /client/clientname 中。 中放入大量这些行来达到预期的效果。
RewriteRule ^client1(.*)$ /client/client1$1 [L]
RewriteRule ^client2(.*)$ /client/client2$1 [L]
我可以通过在 .htaccess:等
我试图通过检查 /client 中是否存在客户端目录来以更干净的方式执行此操作。 (如果我确定它不是一个有效的文件或目录)。但由于某种原因,这似乎不起作用:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond /client/%{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /client/$1 [L,QSA]
我错过了什么?
I have a situation where I have several clients, each of which I'd like to be able to access their site via mydomain.com/clientname. To keep things organized, I store the actual files for the client's sites in /client/clientname. I can achieve the desired effect by putting lots and lots of these lines in my .htaccess:
RewriteRule ^client1(.*)$ /client/client1$1 [L]
RewriteRule ^client2(.*)$ /client/client2$1 [L]
etc.
I'm trying to do this in a cleaner way, by checking if the client directory exists in /client or not. (If I've determined that it's not an otherwise valid file or directory). But for some reason this seems to not be working:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond /client/%{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /client/$1 [L,QSA]
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 Apache mod_rewrite 文档:
REQUEST_FILENAME
与请求匹配的文件或脚本的完整本地文件系统路径(如果服务器在引用 REQUEST_FILENAME 时已经确定了该路径)。否则,例如在虚拟主机上下文中使用时,与 REQUEST_URI 的值相同。
您的行:
似乎导致了问题,因为它使 Apache 查找以下文件路径:
这肯定不是您想要的。
您可以按如下方式更正:
From the Apache mod_rewrite docs:
REQUEST_FILENAME
The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time REQUEST_FILENAME is referenced. Otherwise, such as when used in virtual host context, the same value as REQUEST_URI.
Your line:
seems to cause the problem, because it makes Apache look for the following file path:
which is quite sure not what you want.
You may correct it as follows: