From 8cc01b7ecccc81a842dce2bbabd6be441989972e Mon Sep 17 00:00:00 2001
From: Rich Bowen We rewrite the old URL to the new one internally via the
following rule: We force a HTTP redirect to the new URL which leads to a
change of the browsers and thus the users view: tags inside
-RewriteEngine on
+
RewriteRule ^/old\.html$ /new.html [PT]
-
-RewriteEngine on
+
RewriteRule ^/foo\.html$ bar.html [R]
-
-RewriteEngine on
+
RewriteRule ^/docs/(.+) http://new.example.com/docs/$1 [R,L]
-
+
Redirect /docs/ http://new.example.com/docs/
-
/~quux/foo.cgi
.
-RewriteEngine on -RewriteBase /~quux/ ++RewriteEngine on
+RewriteBase /~quux/
RewriteRule ^foo\.html$ foo.cgi [H=cgi-script] -
-# backward compatibility ruleset for -# rewriting document.html to document.php -# when and only when document.php exists -<Directory /var/www/htdocs> -RewriteEngine on -RewriteBase /var/www/htdocs - -RewriteCond $1.php -f -RewriteCond $1.html !-f -RewriteRule ^(.*).html$ $1.php ++# backward compatibility ruleset for
+# rewriting document.html to document.php
+# when and only when document.php exists
+<Directory /var/www/htdocs>
++RewriteEngine on </Directory> -
+RewriteBase /var/www/htdocs
+
+RewriteCond $1.php -f
+RewriteCond $1.html !-f
+RewriteRule ^(.*).html$ $1.php
+
For sites running on a port other than 80:
--RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] -RewriteCond %{HTTP_HOST} !^$ -RewriteCond %{SERVER_PORT} !^80$ ++RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
+RewriteCond %{HTTP_HOST} !^$
+RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/?(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R,NE] -
And for a site running on port 80
--RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] -RewriteCond %{HTTP_HOST} !^$ ++RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
+RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE] -
If you wanted to do this generically for all domain names - that @@ -343,11 +345,11 @@ RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE] example.com, you could use the following recipe:
--RewriteCond %{HTTP_HOST} !^www\. [NC] -RewriteCond %{HTTP_HOST} !^$ ++RewriteCond %{HTTP_HOST} !^www\. [NC]
+RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE] -
These rulesets will work either in your main server configuration
file, or in a We'll use a .htaccess
file placed in the
-RewriteEngine on
-
-# first try to find it in dir1/...
-# ...and if found stop and be happy:
-RewriteCond %{DOCUMENT_ROOT}/dir1/%{REQUEST_URI} -f
-RewriteRule ^(.+) %{DOCUMENT_ROOT}/dir1/$1 [L]
-
-# second try to find it in dir2/...
-# ...and if found stop and be happy:
-RewriteCond %{DOCUMENT_ROOT}/dir2/%{REQUEST_URI} -f
-RewriteRule ^(.+) %{DOCUMENT_ROOT}/dir2/$1 [L]
-
-# else go on for other Alias or ScriptAlias directives,
-# etc.
+
+
+# first try to find it in dir1/...
+# ...and if found stop and be happy:
+RewriteCond %{DOCUMENT_ROOT}/dir1/%{REQUEST_URI} -f
+RewriteRule ^(.+) %{DOCUMENT_ROOT}/dir1/$1 [L]
+
+# second try to find it in dir2/...
+# ...and if found stop and be happy:
+RewriteCond %{DOCUMENT_ROOT}/dir2/%{REQUEST_URI} -f
+RewriteRule ^(.+) %{DOCUMENT_ROOT}/dir2/$1 [L]
+
+# else go on for other Alias or ScriptAlias directives,
+# etc.
RewriteRule ^ - [PT]
-
-HostnameLookups on
-RewriteEngine on
-RewriteMap multiplex txt:/path/to/map.mirrors
-RewriteCond %{REMOTE_HOST} ([a-z]+)$ [NC]
+
+RewriteEngine on
+RewriteMap multiplex txt:/path/to/map.mirrors
+RewriteCond %{REMOTE_HOST} ([a-z]+)$ [NC]
RewriteRule ^/(.*)$ ${multiplex:%1|http://www.example.com/}$1 [R,L]
-
-## map.mirrors -- Multiplexing Map
+
+
+de http://www.example.de/
+uk http://www.example.uk/
+com http://www.example.com/
##EOF##
-foo.32.html
.
This is done with the following ruleset:
-RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.* -RewriteRule ^foo\.html$ foo.NS.html [L] - -RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR] -RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].* -RewriteRule ^foo\.html$ foo.20.html [L] - ++RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.*
+RewriteRule ^foo\.html$ foo.NS.html [L]
+
+RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR]
+RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].*
+RewriteRule ^foo\.html$ foo.20.html [L]
+
RewriteRule ^foo\.html$ foo.32.html [L] -
/puppies
and /canines
by the canonical /dogs
.
-+RewriteRule ^/(puppies|canines)/(.*) /dogs/$2 [R] -
+RedirectMatch ^/(puppies|canines)/(.*) /dogs/$2 -
/about/
:
--RewriteEngine on ++RewriteEngine on
RewriteRule ^/$ /about/ [R] -
Note that this can also be handled using the
-<Directory /var/www/my_blog> - FallbackResource index.php +<Directory /var/www/my_blog>
++ FallbackResource index.php </Directory> -
+
However, in earlier versions of Apache, or if your needs are more @@ -615,24 +617,22 @@ complicated than this, you can use a variation of the following rewrite set to accomplish the same thing:
-<Directory /var/www/my_blog> - RewriteBase /my_blog - - RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-f - RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-d - RewriteRule ^ index.php [PT] +<Directory /var/www/my_blog>
++ RewriteBase /my_blog
+
+ RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-f
+ RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-d
+ RewriteRule ^ index.php [PT]
+</Directory> -
If, on the other hand, you wish to pass the requested URI as a query string argument to index.php, you can replace that RewriteRule with:
RewriteRule (.*) index.php?$1 [PT,QSA] -
Note that these rulesets can be uses in a .htaccess
--
2.50.1