Simplifying my Apache site configuration
I run a website off of a Ubuntu server (10.04 LTS, I think) with Apache, MySQL, and PHP. It serves both HTTP and HTTPS content. Currently, I have two main
Is there a better way of doing this so I don't have to put the same rewrite rules in twice? Could I create a
Thanks for your help!
Here's a modified version of my Apache site configuration file (the real one has more rewrite rules):
<virtualhost *:80="">ServerAdmin webmaster@localhost
DocumentRoot /var/www
<directory>Options FollowSymLinks
AllowOverride None</directory>
<directory var="" www="">Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddType video/webm .webm
Redirect 301 /pricing-and-signup/ /plans-and-pricing/
RewriteEngine on
RewriteRule ^tryv3/?$ /index.php [L]
RewriteRule ^TRYV3/?$ /index.php [L]
RewriteRule ^404/?$ /Error.php?Error=404 [L]
ErrorDocument 404 /404/</directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory "="" usr="" lib="" cgi-bin"="">AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all</directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<directory "="" usr="" share="" doc="">Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128</directory></virtualhost>
<virtualhost xxx.xxx.xxx.xxx:443="">ServerAdmin webmaster@localhost
ServerName [REDACTED]
SSLEngine On
SSLCertificateFile [REDACTED]
SSLCertificateKeyFile [REDACTED]
SSLCertificateChainFile [REDACTED]
DocumentRoot /var/www
<directory>Options FollowSymLinks
AllowOverride None</directory>
<directory var="" www="">Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddType video/webm .webm
Redirect 301 /pricing-and-signup/ /plans-and-pricing/
RewriteEngine on
RewriteRule ^tryv3/?$ /index.php [L]
RewriteRule ^TRYV3/?$ /index.php [L]
RewriteRule ^404/?$ /Error.php?Error=404 [L]
ErrorDocument 404 /404/</directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory "="" usr="" lib="" cgi-bin"="">AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all</directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<directory "="" usr="" share="" doc="">Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128</directory></virtualhost>
The rewrite rules that are repeated:
AddType video/webm .webm
Redirect 301 /pricing-and-signup/ /plans-and-pricing/
RewriteEngine on
RewriteRule ^tryv3/?$ /index.php [L]
RewriteRule ^TRYV3/?$ /index.php [L]
RewriteRule ^404/?$ /Error.php?Error=404 [L]
ErrorDocument 404 /404/
8 Replies
As per the Apache 2.2 documentation,
<virtualhost 1.2.3.4:80="" 1.2.3.4:443="">...</virtualhost>
Regards,
@AlexC:
Hi jzimmerlin,
As per the Apache 2.2 documentation,
simply do: http://httpd.apache.org/docs/2.2/mod/co … irtualhost">http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost <virtualhost 1.2.3.4:80="" 1.2.3.4:443="">...</virtualhost>
Regards,
OK, so I finally got around to trying this. Unless I misunderstood what you meant, this didn't work.
<virtualhost *:80="" 72.14.190.162:443="">ServerAdmin webmaster@localhost
ServerName www.rundowncreator.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/STAR_rundowncreator_com.crt
SSLCertificateKeyFile /etc/apache2/ssl/rundowncreator.com.key
SSLCertificateChainFile /etc/apache2/ssl/PositiveSSL.ca-bundle
DocumentRoot /var/www
<directory>Options FollowSymLinks
AllowOverride None
(REWRITE RULES WOULD GO HERE)</directory>
<directory var="" www="">Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all</directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory "="" usr="" lib="" cgi-bin"="">AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all</directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<directory "="" usr="" share="" doc="">Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128</directory></virtualhost>
…will force SSL on port 80 and 443, which is not what I want. And…
<virtualhost *:80="" 72.14.190.162:443="">ServerAdmin webmaster@localhost
DocumentRoot /var/www
<directory>Options FollowSymLinks
AllowOverride None
(REWRITE RULES WOULD GO HERE)</directory>
<directory var="" www="">Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all</directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory "="" usr="" lib="" cgi-bin"="">AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all</directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<directory "="" usr="" share="" doc="">Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128</directory></virtualhost>
<virtualhost 72.14.190.162:443="">ServerAdmin webmaster@localhost
ServerName www.rundowncreator.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/STAR_rundowncreator_com.crt
SSLCertificateKeyFile /etc/apache2/ssl/rundowncreator.com.key
SSLCertificateChainFile /etc/apache2/ssl/PositiveSSL.ca-bundle</virtualhost>
…gives me:
[Fri May 04 10:00:31 2012] [warn] VirtualHost 72.14.190.162:443 overlaps with VirtualHost 72.14.190.162:443, the first has precedence, perhaps you need a NameVirtualHost directive
Any ideas?