Forum Moderators: phranque

Message Too Old, No Replies

Another mod rewrite question

Before I start wrting my rule, I need to please know the following...

         

Lastwords

9:30 am on Jun 27, 2008 (gmt 0)

10+ Year Member



Can I use mod_rewrite to allow certain IP addresses to a subdomain (say friday.domain.co.uk)? This is a dynamically controlled site/page, which gets it's directory structure from the database (MySQL). So, as soon as you go to friday.domain.co.uk you are directed to friday.domain.co.uk/list

My understanding (and please correct me if I'm wrong), is that if the directory structure doesn't exist in the filesystem which Apache looks at but is dynamically created then mod rewrite won't work.

Thanks in advance for any useful advise.

Lastwords

10:26 am on Jun 27, 2008 (gmt 0)

10+ Year Member



To give you a working example of what I'm trying to do, here is what is inside my .htaccess file:

<Directory /docroot/>
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^192\.168\.1\.1
#RedirectMatch ^friday.domain.co.uk$
RewriteRule .*? - [F]
</Directory>

The RedirectMatch is my main aim, so that if people come to that subdomain, I want them blocked except if they are coming from a specific ip range.

jdMorgan

7:44 pm on Jun 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RedirectMatch is a mod_alias directive; It will not interact with the mod_rewrite directives you've placed around it. Additionally, the syntax of your RewriteRule is invalid -- or at least highly-questionable. If it worked, then the result would be a 403-Forbidden response to any request from 192.168.1.1. See the mod_rewrite documentation.

mod_rewrite code can be written to check for 'file exists' and 'directory exists,' and to take action conditionally based on those checks. But it will always execute unless some other module is interfering with it. It's possible that you may be seeing interference from content-negotiation/MultiViews, which I recommend disabling unless you actually use them.

Jim

Lastwords

8:08 am on Jun 30, 2008 (gmt 0)

10+ Year Member



Thanks for your response.

The RewriteRule was taken from a book, to basically match any string and deny it from that address. It may still be wrong but I have to start somewhere when learning mod_rewrite ;)

I do use content-negotation for various media types. However I'm coming to the conclusion that mod_rewrite isn't the best way for me for access control.

jdMorgan

2:22 pm on Jun 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, MultiViews and mod_rewrite have some "unfortunate" interactions. For simple IP-address-based access control, use mod_access. For more-complex access control, you could use <Location> or <Files> containers, and/or use mod_setenvif plus mod_access.

Jim