Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite guru's help needed

real problem

         

a1_design

6:32 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



I have a big problem with rewrite rules.
How to cut 'user' from url 'user.domain.com', that I can use it in following rewrite rules?
i.e. save 'user' in some variable?
I want to hide real path to files from user.

Example:
Real path: [mike.domain.com...]
Path in user's browser: [mike.domain.com...]

I tried to do like this:

RewriteCond %{HTTP_HOST} [^.]+\.domain\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]

RewriteRule ([^.]+)\.domain\.com(.*)$ index.php?user=$1 [L,NC] - LIKE THIS IT WORKS

RewriteRule ([^.]+)\.domain\.com/images(.*)$ users/$1/images/$2 [L,NC] - BUT LIKE THIS DOESN'T (infinite loop)

Why?

jdMorgan

8:27 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We could really use a little more information here...

You will need to arrange for some part of the input URLs to be different from the output URLs. This is needed in order to prevent looping. In the case of the second rule, you can test for the presence of "/users/" and by-pass the rewrite if it is already present. In the case of the first rule, you can look for the presence of the "user=" querystring name.

After mod_rewrite rewrites a URL, control is passed back to httpd.conf, and then down through any/all .htaccess files in the new URL's filepath. This must be done in order to check for further RewriteRules or other access-control directives that match the new URL-path. So, that is why the rule loops.

I'd also suggest, you add another RewriteCond to exclude rewrites on the "www" subdomain, unless you really want to treat that as a "user."

Maybe the above will help. If not, please describe what you are trying to accomplish, and give several examples if you have more than one (or more than one kind) of rule you want to apply.

Jim