Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite, subdomain matching subpath

         

micromix

2:37 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



Hello everybody! First time with mod_rewrite, and first post...
I am using wildcard DNS and must redirect any URL matching the following
://ZZZ.mydomain.com/forums/YYY/anypath (where ZZZ not equal YYY)
e.g.: the following should be redirected to myerror.html:
://mary.mydomain.com/blogs/jane
://mary.mydomain.com/blogs/jane/
://mary.mydomain.com/bloga/jane/whatever
the following should not be redirected:
://mary.mydomain.com/blogs/mary
://mary.mydomain.com/blogs/mary/
://mary.mydomain.com/bloga/mary/whatever
TIA, your help will greatly appreciated.

jdMorgan

9:19 pm on Feb 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi micromix, and welcome to WebmasterWorld!

Please review our forum charter [webmasterworld.com] to find out how to get the most from this forum. Then post the code you've tested, and ask specific questions if you have any problems. Our charter also contains links to useful resources on this subject.

Jim

micromix

12:11 pm on Feb 27, 2008 (gmt 0)

10+ Year Member



I apologize for not reading the charter before.
All what I could come up with so far is the following
rewrite conditions within a given virtual host "mary"
%{REQUEST_URI} !^/[^/]+/jane/
%{REQUEST_URI} !^/[^/]+/linda/
This is ok as long as I have a few virtual hosts,
but it is not practical as the number increases.
I am sure that there is a way around it. I wish
one could read Wiley's "Mod Rewrite for Dummies"...
Thank you.

jdMorgan

3:44 pm on Feb 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no variable-to-variable comparison function in mod_rewrite, so some of your options are:

  • Host on a POSIX 2003.5 server and use "atomic" back-references. This solution is not generally-portable across servers. This solution depends on commutativity, that is, if A+A is equal to A+B, then A=B.

  • Use RewriteMap to call a script to check for equality of the two variables. This requires httpd.conf or conf.d access.

  • Embed PHP code in the pages to check for equality of the two variables.

  • Include PERL code in the pages to check for equality of the two variables.

  • "Hide" the subdirectory path from the user, and do not allow it to be directly entered, but only "copied" from the requested subdomain to reach the actual filesystem location. See RewriteCond %{THE_REQUEST}, which examines the client request and is not changed by internal rewriting.

    Jim

  •