Apache regex config for mass redirects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The goal: to provide for three kinds of applications and application 
structures (file structure driven here, so you don't have to understand 
what the applications are or do to understand what I'm trying to 
accomplish) in a single front end configuration.

All app servers share same front ends, so they need to share the same 
Apache configuration.  So, this is just like one host, one Apache 
config, one IP. It's complex, but it's actually quite simple once it 
resolves. The file location is universal, so the apache config would 
work on a single host as well as a HAProxy fronted application server.

1st, I have some specified domains which require me to add them to the 
config and then perform an apache graceful (restart). The goal here is 
to get away from the requirement to do a restart by using a redirect or 
reroute file for each of the potential domain names.

# Single app shared space domains based on domain1
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{SERVER_NAME} ^(.*)?\.?(domain1|domain2|domain3)\.(com|net)$
RewriteCond "/mnt/www/domain1_files/maintenance.html" -f
RewriteCond %{SCRIPT_FILENAME} !"/mnt/www/domain1/maintenance.html"
RewriteCond %{SCRIPT_FILENAME} !^(.+).(gif|png|jpg|css|js|swf)$
RewriteRule ^.*$ "/mnt/www/domain1/maintenance.html" [L]
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{SERVER_NAME} ^(.*)?\.?(domain1|domain2|domain3)\.(com|net)$
RewriteRule ^/(.*)$ /mnt/www/domain1/public_html/$1 [L]

So, notice that I'm testing for a particular set of domains, then 
pushing any domain that matches the list to a file location. In this 
case they all share domain1's file source, since it handles all the 
sites that are of like kind. Our application parses the domain based on 
how Apache receives the request - so domain2.com is handled by 
domain1.com's file system and app but the database spits back its 
discrete content.

All these domains are managed by the same software, so they use the same 
file system location. Instead of pushing them to discrete file system 
locations like those below (which go to file/named/after/domain/public_html)

Here's how I serve my directory based websites:

# Production Discrete Sites
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond /mnt/www/production/www.%{SERVER_NAME} -d
RewriteRule ^/(.*)$ http://www.%{SERVER_NAME}/$1 [L]
RewriteCond %{REQUEST_URI} !^/icons/
RewriteRule ^/(.*)$ 
/mnt/www/production/${lowercase:%{SERVER_NAME}}/public_html/$1 [L]

I have two or three of the situations above, where application servers 
run different apps. What I'm trying to figure out is how to redirect 
them based on a redirect file as they come in as an apache server request.

Here's an example of a rewrite rule that works for redirecting to an 
URL. What I need to do is redirect to a file location to serve the 
website's application/files.

# Setup redirect map
RewriteMap redirects txt:/mnt/www/.redirect_map
RewriteMap lowercase int:tolower
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond ${redirects:%{SERVER_NAME}|notfound} !^notfound$
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(/.*)$ http://${redirects:%{SERVER_NAME}}$1 [L]
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond ${redirects:%{SERVER_NAME}|notfound} !^notfound$
RewriteRule ^/$ http://${redirects:%{SERVER_NAME}} [L]

What's I'm trying to do is combine the best of three processes. I'd like 
to add a redirect/cond to send URL requests to an app or file location 
based on the redirect map.

So, instead of a redirect map that looks likes this:

domain1  domain1.com
domain2 domain2.com/domain2content

I'd like to do something more like this:

domain1 /mnt/www/domain1.com
domain2 /mnt/www/domain1.com
domain3 /mnt/www/domain3.com

And so forth.

The goal here is to automate things and cut down on apache restarts. 
Also, I intend to leave the redirect rule that sends all remaining 
www.domain requests to the www.$DOMAIN file location for that website's 
discrete application files.


Opinions, ideas, etc. are solicited.


-- 

Jason A. Nunnelley
http://www.google.com/profiles/imjasonn

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux