LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   apache rewrite help (http://www.linuxquestions.org/questions/linux-server-73/apache-rewrite-help-495776/)

deesto 10-26-2006 10:48 AM

apache rewrite help
 
I'm trying to proxy a server and change the appearance of the server directories for client browsers.

On the proxy server ("proxy"), I've added the following:
Code:

ReWriteEngine On
RewriteRule  ^/dir/ect/ory/$ http://server/directory/ [R]

This works in general, but the browser displays proxy/directory/ instead of proxy/dir/ect/ory/, which is what I would like it to show (is that a transparent proxy?).

I've also had to write additional rules for subdirectories, which tells me I'm probably doing something wrong:

Code:

RewriteRule  ^/dir/ect/ory/subdir$ http://server/directory/subdir [R]
To further complicate things, it doesn't work properly unless I include a ProxyPass directive:
Code:

ProxyPass /directory http://server/directory
ProxyPassReverse /directory http://server/directory

Any thoughts on what I'm doing wrong?

deesto 10-27-2006 11:33 AM

I think a very simple pair of ProxyPass|ProxyPassReverse directives could replace some of this stuff, but not all... what about this on the proxy server:
Code:

ProxyPass /dir/ect/ory http://server/directory
ProxyPassReverse /dir/ect/ory http://server/directory

That seems to do exactly what I need as far as the client-side URL goes.

The problem is the subdirs: I'm doing this because I need to mirror TWiki pages (which are not .HTML files) with their HTML counterparts. The TWiki treats URL space a bit differently (their "webs" and "topics" appear as directories without a trailing slash in the URL). So when you browse to a specific page of the TWiki, you don't append .html to the URL because it doesn't exist. However, it's there on the HTML mirror, and I need something to not ony append the .html suffix to each incoming request, but to be able to tell whether the request is looking for a file or a directory.

The RewriteRule above works for that, if I duplicate it so it appears with and without the trailing slash, and for each subdirectory (I'm sure there's a better way... I can't figure out the syntax to condense it all). But that doesn't help with the URL space issue that ProxyPass seems to help with.

deesto 10-31-2006 08:24 AM

Folks, any ideas on how to get this working, or to improve the methods I've tried? I'd really appreciate your help.

deesto 11-03-2006 02:07 PM

OK... can anyone help me figure out how to clean this up on the proxy's httpd.conf?
Code:

<VirtualHost *:80>
    ServerAdmin webmaster@webserver
    ServerName webserver
    ReWriteEngine On
    RewriteLogLevel 2
    RewriteRule  ^/dir/ect/ory/misc/(\w+)(/.*)$  /directory/$1/misc/$1$2 [P,L]
    RewriteRule  ^/dir/ect/ory/(\w+)/misc(/.*)$  /directory/$1/misc$2 [P,L]
    RewriteRule  ^/dir/ect/misc/(\w+)(/.*)$  /directory/$1/misc/$1$2 [P,L]
    RewriteRule  ^/dir/ect/(\w+)/misc(/.*)$  /directory/$1/misc$2 [P,L]
    RewriteRule  ^/dir/misc/(\w+)(/.*)$  /directory/$1/misc/$1$2 [P,L]
    RewriteRule  ^/dir/(\w+)/misc(/.*)$  /directory/$1/misc$2 [P,L]
    RewriteRule  ^/dir/ect/ory/(\w+)/(\w+).html$  /directory/$1/$2.html [P,L]
    RewriteRule  ^/dir/ect/ory/(\w+).html$  /directory/Main/$1.html [P,L]
    RewriteRule  ^/dir/ect/ory/(\w+)/(\w+)$  /directory/$1/$2.html [P,L]
    RewriteRule  ^/dir/ect/ory/(\w+)/?$  /directory/$1/WebHome.html [P,L]
    RewriteRule  ^/dir/ect/ory/?$  /directory/Main/WebHome.html [P,L]
    RewriteRule  ^/dir/ect/(\w+)/(\w+).html$  /directory/$1/$2.html [P,L]
    RewriteRule  ^/dir/ect/(\w+).html$  /directory/Main/$1.html [P,L]
    RewriteRule  ^/dir/ect/(\w+)/(\w+)$  /directory/$1/$2.html [P,L]
    RewriteRule  ^/dir/ect/(\w+)/?$  /directory/$1/WebHome.html [P,L]
    RewriteRule  ^/dir/ect/?$  /directory/Main/WebHome.html [P,L]
    RewriteRule  ^/dir/(\w+)/(\w+).html$  /directory/$1/$2.html [P,L]
    RewriteRule  ^/dir/(\w+).html$  /directory/Main/$1.html [P,L]
    RewriteRule  ^/dir/(\w+)/(\w+)$  /directory/$1/$2.html [P,L]
    RewriteRule  ^/dir/(\w+)/?$  /directory/$1/WebHome.html [P,L]
    RewriteRule  ^/dir/?$  /directory/Main/WebHome.html [P,L]
    ProxyPass /directory http://webserver/directory
    ProxyPassReverse /directory  http://webserver/directory
</VirtualHost>

It finds all the files and directories, but some of the redirects give screwy URLs, and there's probably a much more efficient way to do all this.

Thanks.


All times are GMT -5. The time now is 11:53 PM.