Skip to content

friends-of-tutorials/apache-vhost-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Apache vhost examples

1. Variables

Some Basics:

# default
RewriteRule .* - [ENV=url:%{HTTP_HOST}]

# overwrite, if the conditions are met (RewriteCond). 
RewriteCond ...
RewriteCond ...
RewriteRule .* - [ENV=url:test.domain.de]

...

1.1 Example: User-agent dependent redirects

Always redirect to current http_host. If a special user-agent is given, rewrite the current http_host.

# url = save current http_host (directly requested "-origin" url should keep the "-origin" url)
RewriteRule .* - [ENV=url:%{HTTP_HOST}]

# url = redirect url without "-origin" if http_user_agent is "Amazon CloudFront"
RewriteCond %{HTTP_USER_AGENT} "Amazon CloudFront"
RewriteCond %{HTTP_HOST}       "^test-origin.domain.de$"
RewriteRule .* - [ENV=url:test.domain.de]

# url = redirect url without "-origin" if http_user_agent is "Amazon CloudFront"
RewriteCond %{HTTP_USER_AGENT} "Amazon CloudFront"
RewriteCond %{HTTP_HOST}       "^www-origin.domain.de$"
RewriteRule .* - [ENV=url:www.domain.de]

# Redirect to non-html if *.html is given
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ https://%{ENV:url}/%1 [NC,L,R]

A. Authors

B. Licence

This tutorial is licensed under the MIT License - see the LICENSE.md file for details

C. Closing words

Have fun! :)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published