Help with rewrite in subfolder/context

#1
Hi,

I'm having trouble setting up rewrite rules for a subfolder on a vhost.

My document root for the vhost is:
/usr/local/lsws/DEFAULT2/

This vhost has following rewrite rules working:

Code:
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^/api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

# Images
RewriteRule ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteRule ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteRule ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteRule ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteRule ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteRule ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteRule ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteRule ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteRule ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]

# AlphaImageLoader for IE and fancybox
RewriteRule ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
Inside there is a folder, let's call it "example" (/usr/local/lsws/DEFAULT2/html/admin123456/example/) for which i have created a static context with following configuration:

Code:
URL: /example/
Location: /usr/local/lsws/DEFAULT2/html/admin123456/example/
Accessible: yes
Enable Rewrite: yes
Rewrite Inherit: no
Rewrite Base: /example/
And following rewrite rules:

Code:
RewriteRule  ^plik,([0-9]*).htm$ index.php?plik=$1
RewriteRule  ^plika,([0-9]*),([^.]*).htm$ index.php?plik=$1&action=$2
RewriteRule  ^login.htm$ index.php?login=1
mywebsite.com/example is working ok

Now when i try to access mywebsite.com/example/login.htm i get a 404 and in error log i see it tries to match the rewrite rules for the VHost, it doesn't even log any Rule: Match for the context. All it does is this:
Code:
[REWRITE] Rule: Match '/example/login.htm' with pattern '^.*$', result: 1
[REWRITE] Source URI: '/example/login.htm' => Result URI: '/index.php'
Which does exactly nothing.

Any help with the setup would be much appreciated.
 

lsfoo

Moderator
#2
Hi Chris737,

Any requests to your virtual host will always go through the vhost rewrite rules, so your request hit the last rewrite rule of your vhost ruleset, which must've rewritten it to /index.php, which will not hit the example context.

Are the requests to that context supposed to go through the vhost rewrite rules? If not, try adding a rule in the vhost ruleset that for all requests that match the context, do not rewrite, and end the ruleset with a [L] flag. This should happen at the latest before the Dispatcher comment, so it doesn't hit those rules.

Let me know how it works,
Kevin
 
Top