Re: Avoid endless loop of mod_rewrite

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9 March 2010 07:57, Michael Menegakis <arxeio@xxxxxxxxx> wrote:
> On Mon, Mar 8, 2010 at 11:12 AM, Philip Wigg <phil@xxxxxxxxxxxxxxxx> wrote:
>> On 8 March 2010 05:17, Michael Menegakis <arxeio@xxxxxxxxx> wrote:
>>> Hi all
>>>
>>> A rule is in place that that rewrites domains to www.domains
>>>
>>> In one particular home dir, I need the opposite,
>>>
>>> RewriteEngine On
>>> RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
>>> RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
>>>
>>> But it goes into an endless loop that eventually makes firefox spit
>>>
>>> 'The page isn't redirecting properly
>>> Firefox has detected that the server is redirecting the request for
>>> this address in a way that will never complete.'
>>>
>>> How to ignore the higher level rule?
>>
>> Can you not add an extra RewriteCond to each rule to check if you are
>> or aren't in the 'one particular home dir' or not? For example:-
>>
>> RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
>> RewriteCond %{REQUEST_URI} ^/homedir/.*                     <-- This
>> rule only applies if we're in /homedir/
>> RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
>>
>> RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
>> RewriteCond %{REQUEST_URI} !^/homedir/.*                     <-- This
>> rule only applies if we're not in /homedir/, note the exclamation
>> mark.
>> RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
>
> I do not have access to the httpd. However, the corporation I'm
> dealing with doesn't seem to mind with rewriting urls per se, it's
> just that it happens this particular hickup is a sideeffect of their
> rules and they have no policy of changing httpd conf just for one of
> their thousand domains just for one particular account (unless they
> buy a server).
>
> So, I was wondering if there's a way .htaccess-side only to just not
> go into an infinite loop.

What was wrong with my suggestion of adding an extra RewriteCond?
Remember if you're configuring rewrites in an .htaccess, you'll
probably need to use RewriteBase:-

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritebase

-- Phil.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux