htaccess Elite

Hire htaccesselite professional

.htaccess tutorial


All times are UTC - 5 hours





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: RedirectMatch RedirectPermanent RedirectTemp
PostPosted: Oct 26th, '06, 03:11 
User avatar

Joined: Sep 24th, '06, 22:48
Posts: 240
Redirect directive
Syntax: Redirect [status] URL-path URL
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Status: Base
Module: mod_alias
Compatibility: The directory and .htaccess context's are only available in versions 1.1 and later. The status argument is only available in Apache 1.2 or later.


The Redirect directive maps an old URL into a new one. The new URL is returned to the client which attempts to fetch it again with the new address. URL-path a (%-decoded) path; any requests for documents beginning with this path will be returned a redirect error to a new (%-encoded) URL beginning with URL.

Code:
[b]Redirect /service http://foo2.bar.com/service [/b]


If the client requests http://myserver/service/foo.txt, it will be told to access http://foo2.bar.com/service/foo.txt instead.

Note: Redirect directives take precedence over Alias and ScriptAlias directives, irrespective of their ordering in the configuration file. Also, URL-path must be a fully qualified URL, not a relative path, even when used with .htaccess files or inside of <Directory> sections.

If no status argument is given, the redirect will be "temporary" (HTTP status 302). This indicates to the client that the resource has moved temporarily. The status argument can be used to return other HTTP status codes:

Quote:
permanent
Returns a permanent redirect status (301) indicating that the resource has moved permanently.
temp
Returns a temporary redirect status (302). This is the default.
seeother
Returns a "See Other" status (303) indicating that the resource has been replaced.
gone
Returns a "Gone" status (410) indicating that the resource has been permanently removed. When this status is used the url argument should be omitted.


Other status codes can be returned by giving the numeric status code as the value of status. If the status is between 300 and 399, the url argument must be present, otherwise it must be omitted.
Note that the status must be known to the Apache code (see the function send_error_response in http_protocol.c).

Example:

Code:
[b]Redirect permanent /one http://example.com/two
    Redirect 303 /two http://example.com/other[/b]


Redirection while changing the filename, but keeping the GET arguments

Sometimes, you will want to change to a different CMS, but keep your database the same, or you want to switch everything but you like the arguments and don't want to change them.

Code:
RedirectMatch 301 /oldcart.php(.*) http://www.newdomain.com/newcart.php$1


This will result in "http://www.olddomain.com/oldcart.php?Cat_ID=Blue" being redirected to "http://www.newdomain.com/newcart.php?Cat_ID=Blue"


Redirection while changing the filename

This example will redirect all the files on the old account that end in html to the same file on the new account, but with a php extension. You can also use this technique within the same account if you want to change all your extensions but don't want to lose your incoming links to the old pages. This is common when people switch to from static htm files to dynamic ones while keeping the same domain name, for example.

Just change the "html" and "php" parts of the below example to your specific situation, if needed.

RedirectMatch 301 (.*)\.html$ http://www.newdomain.com$1.php

RedirectMatch
Syntax: RedirectMatch [status] regex URL
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Status: Base
Module: mod_alias
Compatibility: Available in Apache 1.3 and later


This directive is equivalent to Redirect, but makes use of standard regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename. For example, to redirect all GIF files to like-named JPEG files on another server, one might use:

Code:
   [b]RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg[/b]




RedirectTemp directive
Syntax: RedirectTemp URL-path URL
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Status: Base
Module: mod_alias
Compatibility: This directive is only available in Apache 1.2 and later


This directive makes the client know that the Redirect is only temporary (status 302). Exactly equivalent to Redirect temp.


RedirectPermanent directive
Syntax: RedirectPermanent URL-path URL
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Status: Base
Module: mod_alias
Compatibility: This directive is only available in Apache 1.2 and later


This directive makes the client know that the Redirect is permanent (status 301). Exactly equivalent to Redirect permanent.

301 Redirect Apache for SEO - McAnerin Networks Inc.

Apache Reference: mod_rewrite
RewriteEngine
RewriteOptions
RewriteLog RewriteLogLevel
RewriteLock
RewriteMap
RewriteBase
RewriteCond
RewriteRule


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB