Rewrite might not always be required, when changing one static URL to another URL a Redirect can be used:

#Redirect the base-URL (only) to https
Redirect permanent /
#Redirect a particular uri to another url
Redirect permanent /foo

Redirecting http to https / Force use of SSL

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}


RewriteCond %{SERVER_PORT} ^80$
RedirectRule ^/(.*)$ https://%{HTTP_HOST}/$1 [R=301]

Hiding PHP script names

The following will allow to be accessed via

RewriteRule    ^cars/?$ car_info_v4_5.php [NC,L]

Force the use of the primary hostname

Having multiple ServerName and/or ServerAlias configs will in normal cases create duplicate sites to search engines as Apache will serve pages containing the domain used by the client. It can therefore be preferable to divert users to a the primary domain of your site, by replacing the domain of the URL. The below Rewrite rule will replace if the domain is not .

RewriteCond %{HTTP_HOST} !^www\\.primarydomain\\.com$ [NC]
RewriteRule ^/($|/.*)$1 [R=301]

Move a website to another URL/domain

Below is the rewrite in place that redirects users from the previous domain for this website. Redirects to :

RewriteRule ^/wiki($|/.*)$1 [NC,R=301,L]

See Also

Rewrite on IIS

Regular Expressions

Category:Web Category:Linux