Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite help!

allow and forbidden paths

         

Hulk_hogan

2:14 pm on May 22, 2007 (gmt 0)

10+ Year Member



Hi,

It's the first time with mod_rewrite module,and I'm really in trouble...

I'm using apache reverse funcytionality:

ProxyPass /irj [web.server.com...]
ProxyPassReverse /irj [reverse.server.com...]

#proxy /logon both ways
ProxyPass /logon [web.server.com...]
ProxyPassReverse /logon [reverse.server.com...]

#proxy /webdynpro both ways
ProxyPass /webdynpro [web.server.com...]
ProxyPassReverse /webdynpro [reverse.server.com...]

Under the path /irj/go/km/docs I would like to allow users just to browse under certain paths like:

/irj/go/km/docs/path1 and /irj/go/km/docs/path2 and forbidden all other paths under /irj/go/km/docs ..

It's possible?

Thanks a lot!
Marco

jdMorgan

6:09 pm on May 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can wrap mod_access directives in <Directory> or <Location> containers, or use mod_rewrite.

Jim

Hulk_hogan

6:39 pm on May 22, 2007 (gmt 0)

10+ Year Member



Hi,

I'm trying to use mod_rewrite..

RewriteRule!/irj/go/km/docs/(path1¦path2/(.*) /sorry.html
This role should be allowed only path1 and path2

but it's doesn't work..

Any suggestion?
Thanks,
Marco

jdMorgan

7:07 pm on May 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Three questions:

Where is this code located -- in httpd.conf, or in .htaccess?

If in .htaccess, what is the path to the .htaccess file itself?

Have you enabled FollowSymLinks (required) and do you have a RewriteEngine on directive?

Jim

Hulk_hogan

7:20 pm on May 22, 2007 (gmt 0)

10+ Year Member



Hi Jim,

the code is located in httpd.conf and I enabled the FollowSymLinks and RewriteEngine on

RewriteEngine on
RewriteLog c:/apache/logs/rewrite.log
RewriteLogLevel 3
Options +FollowSymLinks
RewriteRule!/irj/go/km/docs/(path1¦path2/(.*) /sorry.html

I'm missing something?

Thanks,
Marco

jdMorgan

8:12 pm on May 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe just an artifact of posting on the forum, but there was a missing closing parenthese. I suggest:

Options +FollowSymLinks
#
RewriteLog c:/apache/logs/rewrite.log
RewriteLogLevel 3
RewriteEngine on
#
RewriteRule !^/irj/go/km/docs/(path1¦path2)/ - [F]

This assumes that %{DOCUMENT_ROOT}/irj/go/km/docs/path1/ is a valid path -- that is, no path info is missing in that URL-path when your defined document root is prepended to it, and /irj is the site's HTTP root ("home") directory.

Change the broken pipe "¦" character to a solid pipe before use; Posting on this forum modifies the pipe characters.

This should return a 403 response to any request NOT to those two subdirectories. Absolutely everything on your site except those two subdirectories should be inaccessible via HTTP.

We're also assuming that mod_rewrite is compiled-in, LoadModule'd, and AddModule'd.

Just to save time if you still have problems, please tell us how you tested (what URLs, using example.com please, you entered), what the results were, and how those results differed from what you expected. What's in the browser window? Anything in the server error log? etc.

Jim

Hulk_hogan

12:41 pm on May 23, 2007 (gmt 0)

10+ Year Member



Hi,
I didn't inform you that the apache server acts as a reverse proxy.The configuration is:

#Enable reverse-proxying
ProxyVia on
ProxyTimeout 900
ProxyRequests Off
ProxyPreserveHost on
ProxyPass /irj [realserver.com...]
ProxyPassReverse /irj [reverse.com...]

The rule
RewriteRule!^/irj/go/km/docs/(path1¦path2)/ - [F]
blocks everything different from /irj/go/km/docs/path1 and /irj/go/km/docs/path2

I need something like:

# if the path is /irj/go/km/docs
RewriteCond %{REQUEST_URI} ^/irj/go/km/docs/$
# block all subpaths except /irj/go/km/docs/path1 and #/irj/go/km/docs/path2
RewriteRule!^/irj/go/km/docs/(path1¦path2)/ - [F]

I tried it but is not working. Probably it is due to reverse proxy settings? Any suggestions?
Thank you
Marco

[edited by: Hulk_hogan at 1:00 pm (utc) on May 23, 2007]

jdMorgan

2:41 pm on May 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Generally, the mod_proxy directives are processed before the mod_rewrite directives; mod_proxy directives will be applied first, and if the request is then sent to the back-end, the mod_rewrite directives won't be applied to that request at all, meaning that any mod_rewrite directives on the front-end server will apply only to its 'local' files.

So, you will need to put the code onto the server where that path exists. If that path is proxied to the back-end, then the code needs to go on the back-end server.

Alternately, you could remove the mod_proxy directives implementing the reverse proxy, and instead use the [P] flag of mod_rewrite's RewriteRule to implement the reverse proxy. This would allow conditional reverse-proxying, since you could then use mod_rewrite's RewriteCond directives to make the decision whether to reverse-proxy the request or not.

Jim