Page 1 of 1

.htaccess -- can it solve my issues?

Posted: Fri Feb 20, 2009 8:16 am
by alex.barylski
I have the following .htaccess:

Code: Select all

RewriteEngine On
RewriteCond %{HTTP_HOST} !^members\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{REQUEST_URI} ^/members.domain.com($|/.*$)
RewriteRule ^.* https://members.domain.com%1 [R=permanent,L]
php_value session.cookie_domain ".domain.com"
 
#Redirect C:/wamp/www/members.domain.com http://members.domain.com/
I have no idea what it does as I have just recently joined this project, but it seems to enforce SSL when the sub-domain 'members' is accessed? I need to remove that as SSL is not really required anywhere except at login.

Anyways, my real quesiton is this:

I have a directory structure like so:

Code: Select all

www/index.php
www/about.php
www/news.php
www/history.php
[b]www/members/index.php
www/members/about.php
www/members/news.php
www/members/history.php[/b]
The files in 'members' are PHP scripts which essentially pull on the contents of the originals inside docroot. :crazy: :P

Personally I would have just made each a Linux soft link to the originals. This is obviously so that once a user enters the members.domain.com section of the site they can still access the files in the root. Why they cannot just directly access the root files is beyond me and when I have tried to hardcode the paths so the *real* file is invoked the scripts puke all over me.

I'm shooting for a re-write but in the time being I would like to remove all those extraneous files and have the .htaccess file above include the required conditional to essentially pull on the original much like what the individual files are doing.

Maybe even using an index.php as a proxy to pull the contents of the original file into members.domain.com scope, but I wonder if it's possible to do it with just .htaccess???

Any ideas? Should I just a proxy? Problem with proxy is that I cannot do a file_get_contents() as the files are scripts which need to be evaluated so an include would be required...which might actually work.

Unless there is a way to do it in .htaccess alone so that a request to say:

Code: Select all

http://members.domain.com/about_us.php
Would map (*not redirect*) to:

Code: Select all

http://www.domain.com/about_us.php
Cheers,
Alex

Re: .htaccess -- can it solve my issues?

Posted: Fri Feb 20, 2009 11:20 pm
by JAB Creations
Hi Alex,

With Apache I've learned that it's all a matter of just flooding myself with working examples of useful scripts...which is rare since Apache of the big six (XHTML, CSS, JavaScript, Apache, PHP, and MySQL) is generally given the least consideration as far as time is concerned.

First I'd start with removing the 's' in the url on line five. Then I'd set the form's action to specifically use SSL (https://). I think that might be a quick and dirty fix though it may work. Apache is still half Greek to me but here is an example and how I read it...

Code: Select all

<ifmodule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^(redirect.php|example_dir/) - [L]
  RewriteRule !\.(css|cur|exe|gif|gz|html|h3m|ico|jpg|js|mov|mp3|mp4|msi|pdf|pl|png|rar|swf|ttf|txt|wmv|xhtml|xml|xpi|zip)$ index.php
</ifmodule>
Line three, set exceptions to the rule to following for these files and directories.

Line four, unless the file extension is as follows, all requests should be routed to index.php.

Apache remains a moderate if not major weakness for me so I'm not sure how helpful this will be.