homepage Welcome to WebmasterWorld Guest from 54.166.66.204
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Apache If directive problems
Apache 2.4
Readie




msg:4584846
 10:18 am on Jun 17, 2013 (gmt 0)

Hello,

Having a little problem with the <If> directive in Apache, and I've been unable to find someone with the same problem through Google.

The environment I'm working on is EasyPHP (Apache 2.4.4) running on a WinXP box, with the following in the %systemroot%\system32\drivers\etc\hosts file:

127.0.0.1 www.example.co.uk
127.0.0.1 www.example2.co.uk

And I have 4 files in the root directory I'm running the code from: index.php, index2.php, index3.php and .htaccess. Each index file opens PHP, echoes it's own name, then closes PHP (Forgive the names, but this is a simple test for possibility prior to developing for a live system)

The .htaccess file looks like this:
Options +FollowSymlinks 
RewriteEngine On

<If "%{HTTP_HOST} =~ /^(www\.)?example2\.co\.uk$/">
RewriteRule ^.*$ index2.php [L]
</If>
RewriteRule ^.*$ index3.php [L]

example.co.uk goes through fine, I get "index2" printed to the screen.

example2.co.uk however, throws a HTTP 400: Bad Request (Which is a client request error?) - works fine if I comment out the if block in the .htaccess

As far as I can tell, the .htaccess is syntactically correct

Could anyone point out just where I'm going wrong please?

 

Readie




msg:4584858
 11:07 am on Jun 17, 2013 (gmt 0)

Some relevant logs:

[Mon Jun 17 11:59:00.790910 2013] [rewrite:trace3] [pid 4620:tid 1108] mod_rewrite.c(468): [client 127.0.0.1:4351] 127.0.0.1 - - [www.example2.co.uk/sid#9c6aa0][rid#2313e98/initial] [perdir *If/] applying pattern '^.*$' to uri 'C:/Program Files/EasyPHP-DevServer-13.1VC9/data/localweb/'
[Mon Jun 17 11:59:00.790910 2013] [rewrite:trace2] [pid 4620:tid 1108] mod_rewrite.c(468): [client 127.0.0.1:4351] 127.0.0.1 - - [www.example2.co.uk/sid#9c6aa0][rid#2313e98/initial] [perdir *If/] rewrite 'C:/Program Files/EasyPHP-DevServer-13.1VC9/data/localweb/' -> 'index2.php'
[Mon Jun 17 11:59:00.790910 2013] [rewrite:trace3] [pid 4620:tid 1108] mod_rewrite.c(468): [client 127.0.0.1:4351] 127.0.0.1 - - [www.example2.co.uk/sid#9c6aa0][rid#2313e98/initial] [perdir *If/] add per-dir prefix: index2.php -> *If/index2.php

Which proves it is hitting the inner rewrite rule.

As I'm intending to use this if block for per-domain allow/deny rules, I'm satisfied it is working. I'm still curious as to why the rewrite is failing (Or rather, why it's trying to rewrite to "*If/[[REWRITE_TARGET]]"), but it is now purely an academic matter :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved