Web server - Rewrite engine

From XennisWiki
(Redirected from Rewrite engine)
Jump to: navigation, search

A rewrite engine is software located in a Web application framework running on a Web server that modifies a web URL's appearance [...]. Rewritten URLs are used to provide shorter and more relevant-looking links to web pages. The technique adds a layer of abstraction between the files used to generate a web page and the URL that is presented to the outside world. (Wikipedia)

Apache HTTP Server - Module mod_rewrite

Further information: Apache Module mod_rewrite, Umleitungen mit mod_rewrite, mod_rewrite, a beginner’s guide , mod_rewrite FAQ

Flags: Übersicht, Details


See Apache mod_rewrite Examples for more examples.

Simple redirect

.htaccess (File in the directory scripts/apache/redirect)

<IfModule mod_rewrite.c>
# Forwarding of: http://YOUR-DOMAIN.de/scripts/apache/redirect/CSS-FILE-NAME
# to:            http://jigsaw.w3.org/css-validator/validator?uri=http://YOUR-DOMAIN.org/css/CSS-FILE-NAME.css
RewriteEngine on
RewriteBase /scripts/apache/redirect
RewriteRule ^([^/\.]+)/?$ http://jigsaw.w3.org/css-validator/validator?uri=http://YOUR-DOMAIN.org/css/$1.css&profile=css3 [L]


see Use short URL

.htaccess (in the root directory of your omain)

<IfModule mod_rewrite.c>
# Forwarding of: http://YOUR-DOMAIN.org/w/index.php?index.php?title=ARTICLE
# to:            http://YOUR-DOMAIN.org/wiki/ARTICLE
RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ /w/index.php [PT,L,QSA]
RewriteRule ^/*$ /w/index.php [L,QSA]

Redirect HTTP to HTTPS

Further information: Rewrite HTTP to HTTPS

<IfModule mod_rewrite.c>
RewriteEngine On
# Check connection is not already HTTPS
RewriteCond %{HTTPS} !=on
# Redirect to HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

Authorization header

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

See also