Forum Moderators: phranque

Message Too Old, No Replies

modrewrite / htaccess issue

         

tgh003

5:04 pm on May 4, 2007 (gmt 0)

10+ Year Member



I want to rewrite the following:
[xx.mydomain.com...]

This should really translate to a subdirectory on our apache web server that points to:
/usr/local/www/mysite/xx/yy/

This directory needs to be authenticated using mod_auth_pgsql where I can use the parameters of:
xx and yy PLUS a username and password entered (using AuthType basic) to authenticate if the user is allowed to access this directory.

Normally this would use .htaccess, but is it possible to do this more dynamically so we do not need to generate an .htaccess file for every directory?

I can build a SQL statement using mod_auth_pgsql, so thats not a problem, but how do I pass in xx and yy into that sql statement.

I assume I can use mod_rewrite in some form, but am looking for some advice.

Any help is greatly appreciated.

jd01

4:14 pm on May 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi tgh003,

Welcome to WebmasterWorld!

I think what you are looking for is a way to serve the information from:

http://example.com/xx/yy/ to xx.mydomain.com/yy/files/[various_files_and_subdirectories]

While sending the xx & yy as variables to the script.

There should be a couple of possible solutions depending on server configuration if I am understanding the question:

1. If sub.domain.com is 'mapped' to domain.com you should be able to:

# Only rewrite if the sub is not www or there is no sub.
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$
#
# Store 'before the dot' in a backreference
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
#
# Store path preceding the first / in a backreference
RewriteRule ^([^/]+)/files/ /%2/$1?varXX=%2&varYY=$1 [L]

2. If sub.domain.com is not mapped, you will need to Proxy Serve the location:

# Store 'before the dot' in a backreference
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
#
# Store path preceding the first / in a backreference
RewriteRule ^([^/]+)/files/ http://example.com/%1/$1?varXX=%1&varYY=$1 [P]

Not sure if I got it right, but hopefully this will give you some ideas to try.

Please, either try them out, or be *very* specific about where you would like to get the information as 'variables' so maybe we can point you in a direction.

Maybe give us some ideas you have tried unsuccessfully, so we can help you get them working?

Justin