NYCPHP Meetup

NYPHP.org

[nycphp-talk] OT - mod_rewrite Assistance

Joseph Crawford codebowl at gmail.com
Fri Apr 13 23:12:23 EDT 2007


Rob i ended up getting it working :D

I am not sure about the REDIRECT_STATUS but here is what i do know
about the code

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^dev\.((.+)\.)ere\.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^((.+)\.)?ere\.net$ [NC]
RewriteCond $1 !^(index\.php|images|robots\.txt|ZendPlatform|assets|zxcv)(/.*)?$
[NC]
RewriteRule ^(.*)$ /index.php/%2%{REQUEST_URI} [QSA,L]

The second line says that the HTTP HOST must match the pattern
following it, it must start with dev.*.ere.net.

The third condition says that it must start with *.ere.net

The fourth line says ONLY run this rule if the following are not found
in the url.

The last line re-writes the urls so that they all go through /index.php/*/

meaning if i called the following url

http://dev.auth.ere.net/this/is/a/test/
it would be re-written to
http://dev.auth.ere.net/index.php/auth/this/is/a/test/

that would match the second condition.

The issue i was running into is when i was trying to match the following

http://dev.ere.net/this/is/a/test/

it wouldnt see anything since dev. was required and matched so it
would do something like this

http://dev.ere.net//this/is/a/test/

However it is all solved now and will work on our dev domains and
production domains.  Since we are using dynamic sub-domains we needed
a way to route them all to the same index.php file.

Thanks for the response.

On 4/12/07, Rob Marscher <rmarscher at beaffinitive.com> wrote:
> > On Apr 11, 2007, at 1:51 PM, Joseph Crawford wrote:
> > The rule is running properly but never stopping until the browser
> > stops it. if you go to http://dev.sub.domain.com/ it will redirect you
> > to http://dev.sub.domain.com/sub/ but it goes continuosly adding more
> > and more /sub/ to the url.I've hit that problem before... If I
> > remember right, I think it's because when it goes into http://
> > dev.sub.domain.com/sub/ it process the same set of rewrite rules
> > and they still match so it goes and rewrites it again to http://
> > dev.sub.domain.com/sub/sub/
>
> Off the top of my head, I think one simple way to solve it is to put
> a .htaccess file in each of your "subdirectory" folders that simply
> has RewriteEngine On which clears out the rules for that folder so it
> won't try to process the rules of the parent folder.
>
> Either that or you figure out how to put a conditional so that it
> doesn't match the second time around.
>
> > Also i do not wish to show the url in the address bar. All i want to
> > show there is http://dev.sub.domain.com/ but in the background that
> > should rewrite to http://dev.sub.domain.com/sub/
> > So if i type in http://dev.sub.domain.com/folder/ in the background it
> > will actually be calling http://dev.sub.domain.com/sub/folder/
>
> The http://%{HTTP_HOST}/ part of your last rule is causing that.
>
> I'm actually having a bit of trouble deciphering how your rule works
> exactly.  There might be a simpler way to do it.  I guess I could
> RTFM... but if you've got a second to explain in english, what does %
> {ENV:REDIRECT_STATUS} and %3%{REQUEST_URI} do?
>
> -Rob
>
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>


-- 
Joseph Crawford Jr.
Zend Certified Engineer
Codebowl Solutions, Inc.
http://www.codebowl.com/
Blog: http://www.josephcrawford.com/
1-802-671-2021
codebowl at gmail.com



More information about the talk mailing list