HTML and CSS Reference
In-Depth Information
<title>302 Found</title>
<p>The document has moved
<a href="">here</a>
<address>Apache/2 Server at Port 80</address>
Most users never see this. Instead, their browser silently and immediately redirects them to . I was able to move the page but keep the old links working.
Consult your server documentation to determine exactly how this is accomplished with different servers. In the
most popular server, Apache, this is achieved with mod_rewrite rules placed in the httpd.conf or .htaccess files.
For example, the preceding redirect is accomplished with this rule:
RewriteEngine On
RewriteOptions MaxRedirects=10 inherit
RewriteBase /
RewriteRule ^examples(.*) books/jdr/examples$1 [R]
Regular expressions indicate exactly what is rewritten and how. In this case, after turning on the engine and
setting a couple of options to prevent infinite redirect loops, the base for the rewrites is set to / , the root of the
URL hierarchy. This is where all further matches begin.
The actual rule looks for all URLs whose path component begins with /examples , followed by any number of
characters. The ^ character anchors this expression to the rewrite base of / set in the previous line. The .*
matches everything that comes after /examples , and the parentheses around .* enable us to refer back to
those matched characters in the next part of the expression as $1 .
The third string on the last line, books/jdr/examples$1 , is the replacement rule. It replaces the matched string
from the first line with books/jdr/examples/ and the piece that was matched by (.*) in the search string.
Finally, [R] means that the client should be told about the redirect by sending a 302 response. If we left it out,
the new data would still be sent to the client, but it would appear as though it had come from the old URL.
That's usually not what you want, because keeping the same page at several URLs reduces your search engine
impact. (However, such silent redirects are very useful if you're trying to put a sensible URL structure on top of
a messy internal database-backed system. WordPress uses this technique extensively, for example.) If you'd
rather send a 301 Moved Permanently response, change [R] to [R=301] .
This one rule creates many redirects. For instance:
/examples/chapters/01 is redirected to /books/jdr/examples/chapters/01.
/examples is redirected to /books/jdr/examples.
/examples/chapters/01/ is redirected to
Search WWH ::

Custom Search