HTML and CSS Reference
In-Depth Information
By adjusting the regular expression and the base, you can create other redirects. For example, we could
redirect requests for .html files but not .java files:
RewriteRule ^examples(.*)\.html books/jdr/examples$1.html [R]
Or suppose you've changed all your HTML files to end with .xhtml instead of .html. This rule redirects all
requests for .html to new names with .xhtml instead:
RewriteRule ^(.*)\.html $1.xhtml [R]
Rules aren't always so generic. Sometimes you just want to redirect a single file. For example, suppose you
discover you've published a document at /vacation/picures.html and it should really be /vacation/pictures.html.
You can rename the file easily enough and then insert this rule in your .htaccess file so that requests for
/picures.html are now redirected to /vacation/pictures.html:
RewriteRule /vacation/picures.html /vacation/pictures.html [R]
Another common case is when the site name changes. For example, suppose your company changes its name
from Foo Corp to Bar Corp. Of course, you'll continue to hold on to the domain, but you do want
to send users to the new domain. This rule does that:
RewriteCond %{HTTP_HOST} !^www\.bar\.com [NC]
RedirectMatch ^/(.*)$1 [L,R=301]
This says the host is exactly (except for case) and the request should be redirected to , from which the same path and query string will be requested.
Search WWH ::

Custom Search