Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Apache rewrite rules and various sub-directories

I have a quick question about rewrite rules that I havn't been able to crack all day. The problem is thus:
I have a members directory located under / (ie. http://xxx.com/Members/) and I've allowed the members access simply by xxx.com/mymembername/ (redirecting all requests to /Members - no probs), but the thing is ALL requests are processed this way (including requests to /Images, or if they enter /Members/xxx anyway etc). How can I stop this from happening? My rewrite rules thus far:

# don't re-direct /Member/ or /Images/
RewriteCond     ^\/([^\/]+)      ^\/Members.*     [OR]
RewriteCond     ^\/([^\/]+)     ^\/Images.*    
RewriteRule        ^\/([^\/]+)      -                [L]
         
# redirect everything else
RewriteRule      ^\/([^\/]+)(\/.*)   /var/www/xxx.com/Members/$1$2 [L]

What am I missing? Thanks in advance.

/me
0
Mr_Invisible
Asked:
Mr_Invisible
1 Solution
 
bobsledbobCommented:

Just to clean things up a bit, and to make things easier for you, why aren't you just writing your rewrite conditions in the negative (with the ! ), like this:

RewriteCond %{REQUEST_URI} !^/Members/
RewriteCond %{REQUEST_URI} !^/Images/
RewriteRule ^\/([^\/]+)(\/.*) /var/www/xxx.com/Members/$1$2


Does this help?

Some places to reference:

http://httpd.apache.org/docs/mod/mod_rewrite.html
http://httpd.apache.org/docs/misc/rewriteguide.html

0
 
Mr_InvisibleAuthor Commented:
My Apologies, I forgot I had started this thread. I found an answer, and in the event anyone else has the problem my solution is below. BTW I tried negating it, but by the looks of it I was on the wrong track anyway.

<IfModule mod_rewrite.c>
# we want to be able to have the member name as a root folder, but this is messy if we create them in the root folder.So we use mod_rewrite to check if the REQUEST_FILENAME is a directory or file under the /Members/ folder - if it is, then redirect, otherwise check for other patterns.
         
     # Re-Write trickery
     RewriteEngine on
     RewriteLog "/var/log/apache/xxx.com/rewrite.log"
     RewriteLogLevel 1
         
     # redirect these if they exist
     RewriteCond     /var/www/xxx.com/Members%{REQUEST_FILENAME}     -d     [OR]
     RewriteCond     /var/www/xxx.com/Members%{REQUEST_FILENAME}     -f
     RewriteRule     ^/(.*)     http://xxx.com/Members/$1     [L]    

     # Don't redirect these
     RewriteRule ^/Images/     -     [L]
     RewriteRule ^/Members/     -     [L]
     RewriteRule ^/inc/     -     [L]
     RewriteRule ^/MyCMS/     -     [L]
     RewriteRule ^/Admin/     -     [L]
     RewriteRule ^/test/     -     [L]

     # redirect '/xxx/' (assuming xxx is a member) - last chance to redirect something
     RewriteRule ^\/([^\/]+)(\/.*)     http://xxx.com/Members/$1$2     [L]
</IfModule>    

This is what worked for me, the only downside was if the member had an index file the same name as a root file, it would get that instead.
Now, is there anyway to close this thread, or does someone just kill it?

/me
0
 
NetminderCommented:
PAQed, with points refunded (50)

Netminder
Site Admin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now