?
Solved

Apache rewrite rules and various sub-directories

Posted on 2003-03-13
4
Medium Priority
?
179 Views
Last Modified: 2010-03-04
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
Comment
Question by:Mr_Invisible
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Expert Comment

by:bobsledbob
ID: 8185634

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
 

Author Comment

by:Mr_Invisible
ID: 8191937
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
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 11749102
PAQed, with points refunded (50)

Netminder
Site Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question