You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Lee Goddard <le...@gmail.com> on 2011/05/01 17:24:04 UTC

Re: [users@httpd] REQUEST_URI multiple wildcard pattern

Make sure /files does actually exist, otherwise Apache will be applying 
the rewrite rule to whatever your defined ErrorDocument is, if any.

Check the documentation on httpd.apache.org for RewriteLog and 
RewriteLogLevel - they can be VERY helpful. Make sure you remove those 
directives when you are done, you do not want to be logging rewrites on 
a live server.

On 30/04/2011 18:41, Arunkumar Janarthanan wrote:
> Thank you very much Lee, appreciate your assistance with this issue. 
> However with the below rule the URI pattern with actual string even is 
> not working.
>
> Like I said when I try with wget www.xyz.com/files 
> <http://www.xyz.com/files> that goes to www.abc.com/page-not-found 
> <http://www.abc.com/page-not-found>.
>
> RewriteRule !^/(files|admin|user|product|go)$ 
> http://www.abc.com/page-not-found [R=301,NC,L]
>
> Thanks once again for helping me on this.
>
> On Sat, Apr 30, 2011 at 12:00 PM, Lee <leegee@gmail.com 
> <ma...@gmail.com>> wrote:
>
>     Hi Arunkumar
>
>     You have a list of URIs to NOT match for redirection, so begin the
>     pattern, as you did, with !
>
>         RewriteRule !
>
>     You then have a group of top-level directory or files to be
>     ignored, so you can anchor at the start of the URI:
>
>         RewriteRule !^/
>
>     Then put all your dir/file names in braces, delimited by the OR
>     operator, I
>
>         RewriteRule !^/(this|that)
>
>     Then follow with the URI to which everything should be directed
>     that does not match:
>
>     RewriteRule !^/(this|that) http://your-other-host/page-not-page.
>
>     I wasn't quite sure about your spec's use of wildcards, sometimes
>     you have them after an /oblique/, sometimes without, sometimes not
>     at all. I assumed that was a typo, and that every item should have
>     a wildcard star. If that is not the case, please drop me a line
>     off-list.
>
>     HTH
>     Lee
>
>     PS There is a note on wildcards in ! negated patterns, and why to
>     avoid them:
>
>     http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
>
>     Note
>     When using the NOT character to negate a pattern, you cannot
>     include grouped wildcard parts in that pattern. This is because,
>     when the pattern does NOT match (ie, the negation matches), there
>     are no contents for the groups. Thus, if negated patterns are
>     used, you cannot use |$N| in the substitution string!
>
>
>
>     On 30/04/2011 14:05, Arunkumar Janarthanan wrote:
>     >
>
>     > Hi Lee,
>
>     >
>
>     > sorry for posting the requirement as it is, this is what the
>
>     > requirement exactly.
>
>     >
>
>     > 1. http://xyz.com/esweep* - no redirection at all (so urls
>     like
>
>     > esweepconfirm/thank-you/ do not redirect) 2.
>     http://xyz.com/user* -
>
>     > no redirection at all 3. http://xyz.com/files/* - no
>     redirection at
>
>     > all 4. http://xyz.com/admin* - no redirection at all 5.
>
>     > http://xyz.com/go - no redirection at all 6. All other -
>     redirect to
>
>     > http://www.abc.com/page-not-found
>
>     >
>
>     > Best Regards, Arun J
>
>     >
>
>     > On Sat, Apr 30, 2011 at 7:44 AM, Lee Goddard
>     <leegee@gmail.com <ma...@gmail.com>
>
>     > <ma...@gmail.com>> wrote:
>
>     >
>
>     > Hi Arunkumar
>
>     >
>
>     > You wrote,
>
>     >
>
>     >
>
>     > I could use !^/(files|admin|user|product|go), however this
>     would
>
>     > allow all wildcard pattern for the URI string like
>     "user/login" ? or
>
>     > "products/newarrival" ?
>
>     >
>
>     > This is not true. Nothing beginning with the words files, or
>     admin,
>
>     > or user, or product, or go, would match.
>
>     >
>
>     > You do not need to terminate the pattern with a wildcard --
>     you have
>
>     > a match at the beginning.
>
>     >
>
>     > What is it exactly that you are trying to achieve?
>
>     >
>
>     > Lee
>
>     >
>
>     >
>
>     >
>
>     > On 30/04/2011 12:44, Arunkumar Janarthanan wrote:
>
>     >> Thanks Lee, for your reply.
>
>     >>
>
>     >> I could use !^/(files|admin|user|product|go), however
>     this would
>
>     >> allow all wildcard pattern for the URI string like
>     "user/login" ?
>
>     >> or "products/newarrival" ?
>
>     >>
>
>     >> Is why I tried with (.*) but the wildcard string still
>     not getting
>
>     >> picked up by the rule.
>
>     >>
>
>     >> On Sat, Apr 30, 2011 at 2:22 AM, Lee <leegee@gmail.com
>     <ma...@gmail.com>
>
>     >> <ma...@gmail.com>> wrote:
>
>     >>
>
>     >>
>
>     >>
>
>     >> On 30/04/2011 05:46, Arunkumar Janarthanan wrote:
>
>     >>> Hi,
>
>     >>
>
>     >>
>
>     >>
>
>     >>>
>
>     >>
>
>     >>
>
>     >>
>
>     >>> I have a request that the site contains specific
>
>     >> URI pattern
>
>     >>
>
>     >> should
>
>     >>
>
>     >>
>
>     >>
>
>     >>> go to another URL while the other URI patterns
>
>     >> goes to 404
>
>     >>
>
>     >> page of
>
>     >>
>
>     >>
>
>     >>
>
>     >>> external site.
>
>     >>
>
>     >>
>
>     >>
>
>     >>>
>
>     >>
>
>     >>
>
>     >>
>
>     >>> Here below the rule I have written, however this
>
>     >> is not
>
>     >>
>
>     >> working for
>
>     >>
>
>     >>
>
>     >>
>
>     >>> wildcard match of the URI pattern.
>
>     >>
>
>     >>
>
>     >>
>
>     >>>
>
>     >>
>
>     >>
>
>     >>
>
>     >>> RewriteCond %{REQUEST_URI}
>
>     >>
>
>     >>
>
>     >>
>
>     >>>
>
>     >> !^/(files(.*)|admin(.*)|user(.*)|product(.*)|go(.*))$
>
>     >>
>
>     >> RewriteRule .*
>
>     >>
>
>     >>
>
>     >>
>
>     >>> http://www.abc.com/page-not-found
>
>     >> [R=301,NC,L]
>
>     >>
>
>     >> RewriteCond %{REQUEST_URI}
>     !^/(files|admin|user|product|go)
>
>     >>
>
>     >> Round brackets are good for grouping OR clauses
>     (produce|admin),
>
>     >> and good for storing back-references (.*). But you are
>     not using
>
>     >> back-references, so you can drop a lot of those brackets.
>     Also, you
>
>     >> can simply your use of the gobble-everything operator
>     (.*) by
>
>     >> putting it at the end - although why would you need it?
>
>     >>
>
>     >> You simply need to match a few phrases at the beginning
>     of the
>
>     >> string.
>
>     >>
>
>     >> So:
>
>     >>
>
>     >> ! If REQUEST_URI does not match ^ from the start /
>     oblique
>
>     >> (files|admin|user|product|go) any of these phrases
>
>     >>
>
>     >> HTH Lee
>
>     >>
>
>     >>
>
>     >
>
>
>

Re: [users@httpd] REQUEST_URI multiple wildcard pattern

Posted by Arunkumar Janarthanan <ar...@gmail.com>.
Thank you all once again, on assisting with this issue. The requirement was
unclear till we were asked to point all the URL that should not go to
page-not-found page to /index.php.

Now we did not have to create a negation on request_uri rather a simple
RewriteRule to point those pages to index.php.

Arun J

On Sun, May 1, 2011 at 11:24 AM, Lee Goddard <le...@gmail.com> wrote:

>  Make sure /files does actually exist, otherwise Apache will be applying
> the rewrite rule to whatever your defined ErrorDocument is, if any.
>
> Check the documentation on httpd.apache.org for RewriteLog and
> RewriteLogLevel - they can be VERY helpful. Make sure you remove those
> directives when you are done, you do not want to be logging rewrites on a
> live server.
>
>
> On 30/04/2011 18:41, Arunkumar Janarthanan wrote:
>
> Thank you very much Lee, appreciate your assistance with this issue.
> However with the below rule the URI pattern with actual string even is not
> working.
>
> Like I said when I try with wget www.xyz.com/files that goes to
> www.abc.com/page-not-found.
>
> RewriteRule !^/(files|admin|user|product|go)$
> http://www.abc.com/page-not-found [R=301,NC,L]
>
> Thanks once again for helping me on this.
>
>  On Sat, Apr 30, 2011 at 12:00 PM, Lee <le...@gmail.com> wrote:
>
>>  Hi Arunkumar
>>
>> You have a list of URIs to NOT match for redirection, so begin the
>> pattern, as you did, with !
>>
>>     RewriteRule !
>>
>> You then have a group of top-level directory or files to be ignored, so
>> you can anchor at the start of the URI:
>>
>>     RewriteRule !^/
>>
>> Then put all your dir/file names in braces, delimited by the OR operator,
>> I
>>
>>     RewriteRule !^/(this|that)
>>
>> Then follow with the URI to which everything should be directed that does
>> not match:
>>
>> RewriteRule !^/(this|that) http://your-other-host/page-not-page.
>>
>> I wasn't quite sure about your spec's use of wildcards, sometimes you have
>> them after an /oblique/, sometimes without, sometimes not at all. I assumed
>> that was a typo, and that every item should have a wildcard star. If that is
>> not the case, please drop me a line off-list.
>>
>> HTH
>> Lee
>>
>> PS There is a note on wildcards in ! negated patterns, and why to avoid
>> them:
>>
>>
>> http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
>>
>> Note
>> When using the NOT character to negate a pattern, you cannot include
>> grouped wildcard parts in that pattern. This is because, when the pattern
>> does NOT match (ie, the negation matches), there are no contents for the
>> groups. Thus, if negated patterns are used, you cannot use |$N| in the
>> substitution string!
>>
>>
>>
>> On 30/04/2011 14:05, Arunkumar Janarthanan wrote:
>>  >
>>
>> > Hi Lee,
>>
>> >
>>
>> > sorry for posting the requirement as it is, this is what the
>>
>> > requirement exactly.
>>
>> >
>>
>> > 1. http://xyz.com/esweep* - no redirection at all (so urls
>> like
>>
>> > esweepconfirm/thank-you/ do not redirect) 2.
>> http://xyz.com/user* -
>>
>> > no redirection at all 3. http://xyz.com/files/* - no
>> redirection at
>>
>> > all 4. http://xyz.com/admin* - no redirection at all 5.
>>
>> > http://xyz.com/go - no redirection at all 6. All other -
>> redirect to
>>
>> > http://www.abc.com/page-not-found
>>
>> >
>>
>> > Best Regards, Arun J
>>
>> >
>>
>> > On Sat, Apr 30, 2011 at 7:44 AM, Lee Goddard
>> <leegee@gmail.com
>>
>> > <ma...@gmail.com> <le...@gmail.com>> wrote:
>>
>> >
>>
>> > Hi Arunkumar
>>
>> >
>>
>> > You wrote,
>>
>> >
>>
>> >
>>
>> > I could use !^/(files|admin|user|product|go), however this
>> would
>>
>> > allow all wildcard pattern for the URI string like
>> "user/login" ? or
>>
>> > "products/newarrival" ?
>>
>> >
>>
>> > This is not true. Nothing beginning with the words files, or
>> admin,
>>
>> > or user, or product, or go, would match.
>>
>> >
>>
>> > You do not need to terminate the pattern with a wildcard --
>> you have
>>
>> > a match at the beginning.
>>
>> >
>>
>> > What is it exactly that you are trying to achieve?
>>
>> >
>>
>> > Lee
>>
>> >
>>
>> >
>>
>> >
>>
>> > On 30/04/2011 12:44, Arunkumar Janarthanan wrote:
>>
>> >> Thanks Lee, for your reply.
>>
>> >>
>>
>> >> I could use !^/(files|admin|user|product|go), however
>> this would
>>
>> >> allow all wildcard pattern for the URI string like
>> "user/login" ?
>>
>> >> or "products/newarrival" ?
>>
>> >>
>>
>> >> Is why I tried with (.*) but the wildcard string still
>> not getting
>>
>> >> picked up by the rule.
>>
>> >>
>>
>> >> On Sat, Apr 30, 2011 at 2:22 AM, Lee <leegee@gmail.com
>>
>> >> <ma...@gmail.com> <le...@gmail.com>> wrote:
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >> On 30/04/2011 05:46, Arunkumar Janarthanan wrote:
>>
>> >>> Hi,
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>>
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>> I have a request that the site contains specific
>>
>> >> URI pattern
>>
>> >>
>>
>> >> should
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>> go to another URL while the other URI patterns
>>
>> >> goes to 404
>>
>> >>
>>
>> >> page of
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>> external site.
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>>
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>> Here below the rule I have written, however this
>>
>> >> is not
>>
>> >>
>>
>> >> working for
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>> wildcard match of the URI pattern.
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>>
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>> RewriteCond %{REQUEST_URI}
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>>
>>
>> >> !^/(files(.*)|admin(.*)|user(.*)|product(.*)|go(.*))$
>>
>> >>
>>
>> >> RewriteRule .*
>>
>> >>
>>
>> >>
>>
>> >>
>>
>> >>> http://www.abc.com/page-not-found
>>
>> >> [R=301,NC,L]
>>
>> >>
>>
>> >> RewriteCond %{REQUEST_URI}
>> !^/(files|admin|user|product|go)
>>
>> >>
>>
>> >> Round brackets are good for grouping OR clauses
>> (produce|admin),
>>
>> >> and good for storing back-references (.*). But you are
>> not using
>>
>> >> back-references, so you can drop a lot of those brackets.
>> Also, you
>>
>> >> can simply your use of the gobble-everything operator
>> (.*) by
>>
>> >> putting it at the end - although why would you need it?
>>
>> >>
>>
>> >> You simply need to match a few phrases at the beginning
>> of the
>>
>> >> string.
>>
>> >>
>>
>> >> So:
>>
>> >>
>>
>> >> ! If REQUEST_URI does not match ^ from the start /
>> oblique
>>
>> >> (files|admin|user|product|go) any of these phrases
>>
>> >>
>>
>> >> HTH Lee
>>
>> >>
>>
>> >>
>>
>> >
>>
>>
>>
>


-- 
Best Regards,
Arun Janarthanan

       http://www.linkedin.com/in/arunjanarthanan
       http://www.facebook.com/arun.janarthanan
       http://twitter.com/#!/ArunJanarthanan