LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   cleaning up apache RewriteRule entries (http://www.linuxquestions.org/questions/linux-server-73/cleaning-up-apache-rewriterule-entries-509811/)

deesto 12-12-2006 03:36 PM

cleaning up apache RewriteRule entries
 
I have a whole slew of RewriteRules that I'm sure are not optimal. In a nutshell, I would like any requests to:
/dir1/dir2/dir3/file
to go to:
/directory/dir2/dir3/file.html
... but keep the format of the original request (same directory structure, no .html extension).

I'd also like any requests that don't specify a file (/dir1/dir2/dir3) to go to a standard page (Home.html).

And any requests that only specify the first directory (/dir1) should go to a specific standard page (/directory/dir2/dir3/Home.html).

Here's what we have so far, which seems to catch most cases but is a mess:

Code:

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

Is there a better way?


All times are GMT -5. The time now is 01:02 AM.