开发者

Mod Rewrite Directory Checking

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
Re开发者_如何学GowriteCond %{REQUEST_FILENAME} !-d
RewriteCond /client/%{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /client/$1 [L,QSA]

What am I missing?


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:

RewriteCond /client/%{REQUEST_FILENAME} -d

seems to cause the problem, because it makes Apache look for the following file path:

/client/[the whole filesystem path of requested file]

which is quite sure not what you want.

You may correct it as follows:

RewriteCond %{DOCUMENT_ROOT}/client%{REQUEST_URI} -d
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜