LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 05-17-2011, 05:16 PM   #1
ajs418
LQ Newbie
 
Registered: May 2009
Posts: 4

Rep: Reputation: 0
Trying to figure out Apache mod_rewrite and environment variables


To all the Apache experts out there...

I'm trying to configure my httpd.conf file so that I flip an environment variable or comment out a single line at the top of an httpd.conf (it's a proxy server) and "enable" redirects in various Location directives.

In the following example I have two proxy locations (app1 and app2). App1 is under maintenance and I'd like to quickly flip this one line item to force it to redirect to a maintenance page. This does not work...

Code:
<VirtualHost *:port>
RewriteEngine On
SetEnvIf Request_URI "app1" app1maint=yes
#SetEnvIf Request_URI "app2" app1maint=yes

<Location /app1>
RewriteCond %{ENV:app1maint} ^yes$
RewriteRule (.*) http://host:port/app1MaintenancePage.html
</Location>

<Location /app2>
RewriteCond %{ENV:app2maint} ^yes$
RewriteRule (.*) http://host:port/app2MaintenancePage.html
</Location>
</VirtualHost>
This whole thing does work if I put all the Rewrite and Environment directives into the Location directives for each app/location, but that defeats the purpose of this because now an admin has to muck around the httpd.conf file and comment out each line. We have many locations servicing a number of applications so the file can be quite large.

Last edited by ajs418; 05-17-2011 at 05:17 PM.
 
Old 05-21-2011, 07:55 AM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 697

Rep: Reputation: 93
If I were doing this, I would create a set of files, one for
each configuration. Then put in an include statement in the
httpd.conf that points to the current configuration.

For example, create a file named "app-normal.conf" with both
apps enabled. Create one named "app-1maint.conf" set to enable
only app2. Finally create one named "app-2maint.conf" set to
enable only app1.

Next I would create a soft link from whichever configuration
you want to enable. For example "ln -s app-normal.conf app.conf".
You would then remove the VirtualHost settings from the httpd.conf
file, and replace them with "Include app.conf". Restart the
web service and make sure it works.

After this initial setup, all you need to do to change modes
is run "ln -sf app-???.conf app.conf" and restart the webserver.

I hope my explanation makes sense. Ask if you have any questions!
 
1 members found this post helpful.
Old 05-30-2011, 11:27 AM   #3
ajs418
LQ Newbie
 
Registered: May 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Thumbs up

Thanks for the answer, and you're response definitely makes perfect sense. The only downside is that we've got about 4 applications being serviced by this proxy (maybe a few more in the future), so all the combinations and permutations of apps being up or down could result in all sorts of different conf files.

I ended up just putting a single rewrite rule per application at the beginning of the vhost directive (before all the Location directives) so it is just a matter of uncommenting one line to put up the "maintenance" page.

Thanks for your suggestion!

Quote:
Originally Posted by carltm View Post
If I were doing this, I would create a set of files, one for
each configuration. Then put in an include statement in the
httpd.conf that points to the current configuration.

For example, create a file named "app-normal.conf" with both
apps enabled. Create one named "app-1maint.conf" set to enable
only app2. Finally create one named "app-2maint.conf" set to
enable only app1.

Next I would create a soft link from whichever configuration
you want to enable. For example "ln -s app-normal.conf app.conf".
You would then remove the VirtualHost settings from the httpd.conf
file, and replace them with "Include app.conf". Restart the
web service and make sure it works.

After this initial setup, all you need to do to change modes
is run "ln -sf app-???.conf app.conf" and restart the webserver.

I hope my explanation makes sense. Ask if you have any questions!
 
Old 06-03-2011, 07:22 AM   #4
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 697

Rep: Reputation: 93
Just a thought...your httpd.conf file is probably pretty large and it
might be simpler to comment a line if you put the 4 rewrite rules in
a separate file (named maintenance.conf?) and then put in a line to
include this file.

This would be especially helpful if you have multiple people who may
need to enable or disable the apps.
 
  


Reply

Tags
apache, httpd, modrewrite


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to enable Apache mod_rewrite, after apache installed without this modue jCash Linux - Newbie 1 10-24-2006 10:23 AM
[LaTeX] Centreing a xymatrix in figure environment solarize Linux - Software 3 06-13-2005 01:44 AM
Apache Mod_rewrite help! soulsniper Linux - Software 0 01-16-2005 05:23 PM
Apache:mod_rewrite MadMikie Linux - Software 0 08-03-2004 07:33 AM
Apache and mod_rewrite notsoevil Linux - General 0 01-23-2002 01:39 PM


All times are GMT -5. The time now is 07:36 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration