Reputation: 2841
I've got a simple local site with this directory structure:
/
test2/
.htaccess
bootstrap.php
git-service/
bootstrap.php
What i'm trying to accomplish is that when the user requests www.example.com/test2/git/ he gets the contents of the git-service directory, while if he tries to request the directory git-service directly (www.example.com/test2/git-service/), this request is treated as a normal request (for example given as a GET value to the main test2/bootstrap.php).
What i did by now is this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /test2
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} ^/test2/git($|/.*$)
RewriteRule . /test2/git-service/bootstrap.php?request=GIT [L]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} ^/test2/git-service($|/.*$)
RewriteRule . /test2/bootstrap.php [L]
The problem is that both /test2/git, and /test2/git-service requests are passed to the main bootstrap.php file (test2/bootstrap.php). If i comment out the second block (the one which handles git-service requests) the behaviour is correct, meaning that test2/git requests are correctly passed to git-service/bootstrap.php file. But when i activate the second part, the same requests to test2/git/ as before are now passed to the main test2/bootstrap.php file.
As a side not, the reasoning behind all of this is that i'm trying to decouple the actual name of the directory from the requests made to get it and its contents.
Thank you very much in advance.
====EDIT====
Thank you a lot, anubhava, your suggestion worked very well, albeit needing a minor change, since the server kept giving me 404 errors while requesting git/ pages (git-service pages were mapped correctly).
The code that worked for me is this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /test2/
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
#RewriteRule ^git(/.*|)$ git-service/bootstrap.php?request=GIT [L,NC]
RewriteCond %{REQUEST_URI} ^/test2/git(|/.*)$
RewriteRule . /test2/git_service/bootstrap.php?request=GIT [L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^git-service(|/.*)$ bootstrap.php [L,NC]
For some reason I cannot remove the second RewriteCond line, and I cannot substitute the all-matching dot in the first RewriteRule with the actual condition, or I get 404 errors.
Upvotes: 2
Views: 1198
Reputation: 785481
Have your code like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /test2/
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^git(/.*|)$ git-service/bootstrap.php?request=GIT [L,NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^git-service(/.*|)$ bootstrap.php [L,NC]
Upvotes: 2