Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to allow multiple rewrite rules and rewrite rule/condition pairs #373

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5e5c90b
Setting up the ability to do multiple rewrites and conditions. Allowi…
amvapor Sep 20, 2013
2b23fc6
Changing the syntax of the directives. Now the rewrite directive is m…
amvapor Sep 20, 2013
68eb53d
filling out the documentation a little more thoroughly
amvapor Sep 20, 2013
f04024a
filling out the documentation a little more thoroughly
amvapor Sep 20, 2013
15cab8e
adding validation to the rewrites param
amvapor Sep 21, 2013
7001d39
adding better tests for the new rewrite settings
amvapor Sep 21, 2013
f5d0bcb
make sure at least the first rewrite is a valid hash
amvapor Sep 23, 2013
b7e498c
adding warnings for depricated parameters
amvapor Sep 26, 2013
fa78de0
fixing spelling mistake
amvapor Sep 26, 2013
28b27dd
setting up real tests of rewrites
amvapor Oct 9, 2013
e9f1606
Setting up the ability to do multiple rewrites and conditions. Allowi…
amvapor Sep 20, 2013
2111054
Changing the syntax of the directives. Now the rewrite directive is m…
amvapor Sep 20, 2013
7e9374d
filling out the documentation a little more thoroughly
amvapor Sep 20, 2013
52d63ed
filling out the documentation a little more thoroughly
amvapor Sep 20, 2013
5922eb3
adding validation to the rewrites param
amvapor Sep 21, 2013
e82c4ff
adding better tests for the new rewrite settings
amvapor Sep 21, 2013
9ed974f
make sure at least the first rewrite is a valid hash
amvapor Sep 23, 2013
5fb6c52
adding warnings for depricated parameters
amvapor Sep 26, 2013
cd3358a
fixing spelling mistake
amvapor Sep 26, 2013
10ad280
setting up real tests of rewrites
amvapor Oct 9, 2013
ce718da
merging master
amvapor Nov 9, 2013
07d7465
fixing a misstype
amvapor Nov 12, 2013
c80fa2f
renaming the rewrite_conds and rewrite_rules parameters to be singula…
amvapor Nov 12, 2013
443d33e
added $service_name parameter
ptomulik Nov 4, 2013
019f96c
Merge branch 'master' of github.com:amvapor/puppetlabs-apache
amvapor Nov 12, 2013
96fc7ed
Setting up the ability to do multiple rewrites and conditions. Allowi…
amvapor Nov 14, 2013
2fae0fe
Merge branch 'master' of https://github.com/amvapor/puppetlabs-apache
Nov 14, 2013
9ad3e70
Reworking broken match and notmatch code
Nov 13, 2013
8d8896c
remove unecessary " from around paths in Directory and ScriptAlias de…
Nov 15, 2013
816b629
Fixing incorrect match strings and regexes
Nov 15, 2013
4316ac0
the ssl parameter needs to be true to test the SSL parameters.
Nov 17, 2013
b6ccfb7
Add missing SSL directive tests.
Nov 18, 2013
823e952
Fixing broken test matches...
Nov 18, 2013
a0d2000
Add WSGIPythonPath as an optional parameter to mod_wsgi. This parame…
ksexton Nov 13, 2013
ba1a98a
Merge pull request #473 from antaflos/directories_remove_extra_newlines
igalic Nov 19, 2013
4c34942
Merge pull request #458 from ksexton/wsgi
igalic Nov 19, 2013
e8b1ea7
Setting up the ability to do multiple rewrites and conditions. Allowi…
amvapor Sep 20, 2013
0a5b2fc
added $service_name parameter
ptomulik Nov 4, 2013
543fc2c
Merging upstream and rebasing
Nov 19, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 56 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ To *use* SSL with a virtual host, you must either set the`default_ssl_vhost` par
class { 'apache::mod::wsgi':
wsgi_socket_prefix => "\${APACHE_RUN_DIR}WSGI",
wsgi_python_home => '/path/to/virtenv',
wsgi_python_path => '/path/to/virtenv/site-packages',
}
```
####Defined Type: `apache::vhost`
Expand Down Expand Up @@ -883,44 +884,88 @@ Specifies additional request headers.

#####`rewrite_base`

Limits the `rewrite_rule` to the specified base URL. Defaults to 'undef'.
Limits the `rewrites` to the specified base URL. Defaults to 'undef'.

```puppet
apache::vhost { 'site.name.fdqn':
rewrite_rule => '^index\.html$ welcome.html',
rewrite_base => '/blog/',
rewrites => [
{ rewrite_rule => ['^index\.html$ welcome.html'] }
]
}
```

The above example would limit the index.html -> welcome.html rewrite to only something inside of http://example.com/blog/.

#####`rewrite_cond`
#####`rewrites`

Rewrites a URL via `rewrite_rule` based on the truth of specified conditions. For example
Creates URL rewrite rules. Defaults to 'undef'. This parameter allows you to specify, for example, that anyone trying to access index.html will be served welcome.html.

```puppet
apache::vhost { 'site.name.fdqn':
rewrite_cond => '%{HTTP_USER_AGENT} ^MSIE',
rewrites => [ { rewrite_rule => ['^index\.html$ welcome.html'] } ]
}
```

will rewrite URLs only if the visitor is using IE. Defaults to 'undef'.
Allows rewrite conditions, that when true, will execute the associated rule. For example

```puppet
apache::vhost { 'site.name.fdqn':
rewrites => [
{
comment => 'redirect IE',
rewrite_cond => ['%{HTTP_USER_AGENT} ^MSIE'],
rewrite_rule => ['^index\.html$ welcome.html'],
}
]
}
```

*Note*: At the moment, each vhost is limited to a single list of rewrite conditions. In the future, you will be able to specify multiple `rewrite_cond` and `rewrite_rules` per vhost, so that different conditions get different rewrites.
will rewrite URLs only if the visitor is using IE.

#####`rewrite_rule`
Multiple conditions can be applied, the following will rewrite index.html to welcome.html only when the browser is lynx or mozilla version 1 or 2

Creates URL rewrite rules. Defaults to 'undef'. This parameter allows you to specify, for example, that anyone trying to access index.html will be served welcome.html.
```puppet
apache::vhost { 'site.name.fdqn':
rewrites => [
{
comment => 'Lynx or Mozilla v1/2',
rewrite_cond => ['%{HTTP_USER_AGENT} ^Lynx/ [OR]', '%{HTTP_USER_AGENT} ^Mozilla/[12]'],
rewrite_rule => ['^index\.html$ welcome.html'],
}
]
}
```

Multiple rewrites and conditions are also possible

```puppet
apache::vhost { 'site.name.fdqn':
rewrite_rule => '^index\.html$ welcome.html',
rewrites => [
{
comment => 'Lynx or Mozilla v1/2',
rewrite_cond => ['%{HTTP_USER_AGENT} ^Lynx/ [OR]', '%{HTTP_USER_AGENT} ^Mozilla/[12]'],
rewrite_rule => ['^index\.html$ welcome.html'],
},
{
comment => 'Internet Explorer',
rewrite_cond => ['%{HTTP_USER_AGENT} ^MSIE'],
rewrite_rule => ['^index\.html$ /index.IE.html [L]'],
},
}
rewrite_rule => ['^index\.cgi$ index.php', '^index\.html$ index.php', '^index\.asp$ index.html'],
}
]
}
```

refer to the [`mod_rewrite` documentation](http://httpd.apache.org/docs/current/mod/mod_rewrite.html) for more details on what is possible with rewrite rules and conditions

#####`scriptalias`

Defines a directory of CGI scripts to be aliased to the path '/cgi-bin'
Expand Down Expand Up @@ -1059,7 +1104,7 @@ An array of strings example:
}
```

#####`sslproxyengine`
#####`ssl_proxyengine`

Specifies whether to use `SSLProxyEngine` or not. Defaults to `false`.

Expand Down
Binary file added manifests/.params.pp.swp
Binary file not shown.
2 changes: 2 additions & 0 deletions manifests/mod/wsgi.pp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
class apache::mod::wsgi (
$wsgi_socket_prefix = undef,
$wsgi_python_path = undef,
$wsgi_python_home = undef,
){
apache::mod { 'wsgi': }

# Template uses:
# - $wsgi_socket_prefix
# - $wsgi_python_path
# - $wsgi_python_home
file {'wsgi.conf':
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
'suphp' => 'libapache2-mod-suphp',
'wsgi' => 'libapache2-mod-wsgi',
'xsendfile' => 'libapache2-mod-xsendfile',
'nss' => 'libapache2-mod-nss',
}
$mod_libs = {
'php5' => 'libphp5.so',
Expand Down
54 changes: 45 additions & 9 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@
# docroot => '/path/to/docroot',
# }
#
# # Multiple Mod Rewrites:
# apache::vhost { 'site.name.fqdn':
# port => '80',
# docroot => '/path/to/docroot',
# rewrites => [
# {
# comment => 'force www domain',
# rewrite_cond => ['%{HTTP_HOST} ^([a-z.]+)?example.com$ [NC]', '%{HTTP_HOST} !^www. [NC]'],
# rewrite_rule => ['.? http://www.%1example.com%{REQUEST_URI} [R=301,L]']
# },
# {
# comment => 'prevent image hotlinking',
# rewrite_cond => ['%{HTTP_REFERER} !^$', '%{HTTP_REFERER} !^http://(www.)?example.com/ [NC]'],
# rewrite_rule => ['.(gif|jpg|png)$ - [F]']
# },
# ]
# }
#
# # SSL vhost with non-SSL rewrite:
# apache::vhost { 'site.name.fqdn':
# port => '443',
Expand All @@ -48,8 +66,13 @@
# }
# apache::vhost { 'site.name.fqdn':
# port => '80',
# rewrite_cond => '%{HTTPS} off',
# rewrite_rule => '(.*) https://%{HTTPS_HOST}%{REQUEST_URI}',
# rewrites => [
# {
# comment => "redirect non-SSL traffic to SSL site",
# rewrite_cond => ['%{HTTPS} off'],
# rewrite_rule => ['(.*) https://%{HTTPS_HOST}%{REQUEST_URI}']
# }
# ]
# }
# apache::vhost { 'site.name.fqdn':
# port => '80',
Expand Down Expand Up @@ -81,6 +104,7 @@
$ssl_verify_client = undef,
$ssl_verify_depth = undef,
$ssl_options = undef,
$ssl_proxyengine = false,
$priority = undef,
$default_vhost = false,
$servername = $name,
Expand Down Expand Up @@ -108,7 +132,6 @@
$scriptaliases = [],
$proxy_dest = undef,
$proxy_pass = undef,
$sslproxyengine = false,
$suphp_addhandler = $apache::params::suphp_addhandler,
$suphp_engine = $apache::params::suphp_engine,
$suphp_configpath = $apache::params::suphp_configpath,
Expand All @@ -118,6 +141,7 @@
$redirect_status = undef,
$rack_base_uris = undef,
$request_headers = undef,
$rewrites = undef,
$rewrite_rule = undef,
$rewrite_cond = undef,
$setenv = [],
Expand Down Expand Up @@ -152,7 +176,20 @@
validate_bool($error_log)
validate_bool($ssl)
validate_bool($default_vhost)
validate_bool($sslproxyengine)
validate_bool($ssl_proxyengine)
if $rewrites {
validate_array($rewrites)
validate_hash($rewrites[0])
}

# Deprecated backwards-compatibility
if $rewrite_rule {
warning('Apache::Vhost: parameter rewrite_rule is deprecated in favor of rewrites')
}
if $rewrite_cond {
warning('Apache::Vhost parameter rewrite_cond is deprecated in favor of rewrites')
}

if $wsgi_script_aliases {
validate_hash($wsgi_script_aliases)
}
Expand Down Expand Up @@ -281,9 +318,9 @@
}

# Load mod_rewrite if needed and not yet loaded
if $rewrite_rule {
if ! defined(Class['apache::mod::rewrite']) {
include apache::mod::rewrite
if $rewrites or $rewrite_cond {
if ! defined(Apache::Mod['rewrite']) {
apache::mod { 'rewrite': }
}
}

Expand Down Expand Up @@ -390,8 +427,7 @@
# requestheader fragment:
# - $request_headers
# rewrite fragment:
# - $rewrite_rule
# - $rewrite_cond
# - $rewrites
# scriptalias fragment:
# - $scriptalias
# - $scriptaliases
Expand Down
Loading