Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite redirects HELP ME PLEASE!

Having trouble protecting a directory.

         

phpJoeMo

6:58 pm on May 26, 2011 (gmt 0)

10+ Year Member



So basically what I'm trying to achieve is to protect the following directories:

common
application

I have a central handling script that controls what is seen:

RewriteEngine on

RewriteCond %{IS_SUBREQ} =false [OR]
RewriteCond %{REQUEST_URL} ^/common.*$
RewriteRule ^common.*$ /common/tech/handler.php?toto=home [L]
RewriteRule ^$ /common/tech/handler.php?toto=home [L,QSA]
RewriteRule ^(register|pricing) /common/tech/handler.php?toto=$1 [L,QSA]
RewriteRule ^app/([^/]*) /common/tech/handler.php?app=$1 [NC,L]
RewriteRule ^application.* /common/tech/handler.php?toto=home [L]


any request to application is successfully blocked.
But common as you can tell is getting internal server errors.

Any help would be greatly appreciated.

Thanks

g1smd

7:04 pm on May 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Requests for "example.com/common<anything>" results in an infinite rewrite loop as the internal rewritten path re-matches the RewriteRule pattern.

All of your rules invite Duplicate Content due to poor pattern matching, ambiguous end tags, and unchecked parts of the requested path.

For example, requests for
example.com/app/<something>/<any-junk-here>
will be rewritten. The "any-junk-here" part of the request isn't validated. It should be validated OR you should add an end anchor to disallow anything after
example.com/app/<something>
using
app/[^/]+$
or similar. The pattern allows URL requests with an extension to be rewritten. Is that what you want? If not then ] is more appropriate.

Similar problems occur in the other rules.


Lost my web connection during posting. Edited.

[edited by: g1smd at 7:27 pm (utc) on May 26, 2011]

phpJoeMo

7:19 pm on May 26, 2011 (gmt 0)

10+ Year Member



Thank you.

Isn't the L flag supposed to stop further processing?

Sorry for being such a noob. I'm reading the documentation and trying like mad to comprehend this. Can you elaborate further on my mistakes?

g1smd

7:26 pm on May 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The [L] flag stops processing if the rule matches, but not before mod_rewrite goes "once more round the file" to make sure there are no further matches.

phpJoeMo

9:07 pm on May 26, 2011 (gmt 0)

10+ Year Member



Ok, so I've tried to clean things up based on your recommendations:

RewriteCond %{IS_SUBREQ} false
RewriteCond %{REQUEST_URI} ^common
RewriteRule ^common / [R=301]
RewriteRule !^(register|pricing|common|app) /common/tech/handler.php?toto=home [L]
RewriteRule ^(register|pricing) /common/tech/handler.php?toto=$1 [L]
RewriteRule ^app/([^/]*) /common/tech/handler.php?app=$1 [L]
RewriteRule ^application / [R=301]


Everything is working great with the exception of any requests that begin with common.

What am I missing?

When I view mysite.com/common

I am simply taken to an empty page thus:

mysite.com/common/

Please help me g1smd. I'm calling on your powers! :)

g1smd

9:16 pm on May 26, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"If not then ] is more appropriate."
should have said
"If not then
[^/.]
is more appropriate."


External redirects need the protocol and domain name added, and use the [R=301,L] flags.

You must list the external redirects before the internal rewrites.

You still have unanchored patterns on your internal rewrites.

phpJoeMo

9:43 pm on May 26, 2011 (gmt 0)

10+ Year Member




"If not then ] is more appropriate."
should have said
"If not then [^/.] is more appropriate."

I'm sorry g1smd, but which line in my code were your referring to?

phpJoeMo

10:16 pm on May 26, 2011 (gmt 0)

10+ Year Member




RewriteCond %{IS_SUBREQ} false
RewriteCond %{REQUEST_URI} ^common
RewriteRule ^common / [R=301,L]
RewriteRule !^(register|pricing|common|app) /common/tech/handler.php?toto=home [L]
RewriteRule ^(register|pricing) /common/tech/handler.php?toto=$1 [L]
RewriteRule ^app/([^/.]*) /common/tech/handler.php?app=$1 [L]
RewriteRule ^application / [R=301,L]


Is line 6 what you were referring to?