• Aucun résultat trouvé

mod_alias

Dans le document Apache Server2 Apache Server2 (Page 176-179)

The mod_aliasmodule is compiled by default in Apache. It provides various direc-tives that can be used to map one part of the server’s file system to another, or even to perform URL redirection services.

Alias

The Aliasdirective enables you to map a path to anywhere in your system’s file system.

Syntax:Alias URL-path path Context: Server config, virtual host

For example, the following directive maps /data/ to /web/data; therefore, when a request such as http://www.yoursite.com/data/:

Alias /data/ “/web/data/”

http://data/datafile.cvsis received, the file called /web/data/datafile.cvs is returned.

The aliased path does not have to reside inside your document root tree, so be careful when you create aliases — you might accidentally reveal some part of your file system to the entire world.

If you use a trailing /(slash) in defining an alias, the requests that are capable of accessing the aliased directory also need to contain a trailing /.

Note Caution

AliasMatch

The AliasMatchdirective is similar to the Aliasdirective, except that it can make use of regular expressions.

Syntax:AliasMatch regex path Context: Server config, virtual host For example, the following directive matches

www.yoursite.com/data/index.htmlto the /web/data/index.htmlfile:

AliasMatch ^/data(.*) /web/data$1

Redirect

The Redirectdirective redirects a URL request to another URL. If you have moved a section of your Web site to a new directory or even a new Web site, you can use this directive to ensure that people who have bookmarked the old site are still able to find it.

Syntax:Redirect [status_code] old_URL new_URL

Context: Server config, virtual host, directory, per-directory access control file (.htaccess)

For example, the following directive redirects all URL requests containing the /data path to the new URL. Therefore, requests for www.yoursite.com/data/some-file.txtare redirected to www.your-new-site.com/data/somefile.txt:

Redirect /data www.your-new-site.com/data

The Redirectdirective has precedence over the Aliasand ScriptAlias direc-tives. By default, the status code sent to the client is Temp (HTTP status code 302).

If you want to specify a different status code, use the following:

Status Code What It Does

Permanent Tells the client that the redirect is permanent. The HTTP status code 301 is returned.

Temp Returns a temporary redirect status (302). This is the default.

See other 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.

You can provide valid HTTP status codes in numeric format as well. If the status you provide is between 300 and 399, the new-URL must be present; otherwise, it must be omitted. You may wonder about the use of different status codes. In the future, clients may be smart enough to recognize the status codes in a more meaningful manner. For example, if a proxy server receives a permanent redirect status code, it can store this information in a cache so that it can directly access the new resource in a later request.

RedirectMatch

The RedirectMatchdirective is similar to the Redirectdirective, but it accepts regular expressions instead of the simple old URL.

Syntax:RedirectMatch [status_code] regex URL Context:Server config, virtual host

For example, the following directive redirects all requests that end with .htmto an .htmlversion of the same request:

RedirectMatch (.*)\.htm$ www.yourserver.com$1.html As an example of how this would work, the following request:

http://www.yoursite.com/some/old/dos/files/index.htm is redirected to:

http://www.yoursite.com/some/old/dos/files/index.html See the Redirect directive (last section) for information on status_code.

RedirectTemp

The RedirectTempdirective is similar to the Redirectdirective. It lets the client know that the redirect is only temporary. Note that the Redirectdirective also produces a temporary status by default.

Syntax:RedirectTemp old_URL new_URL

Context:Server config, virtual host, directory, per-directory access control file (.htaccess)

RedirectPermanent

The RedirectPermanentdirective is similar to the Redirectdirective. It lets the client know that the redirect is permanent. Note that the Redirectdirective pro-duces a temporary status by default, but you can use the status code 301 or the keyword permanent, as the status does, the same as this directive.

Note

Syntax:RedirectPermanent old_URL new_URL

Context:Server config, virtual host, directory, per-directory access control file (.htaccess)

ScriptAlias

The ScriptAliasdirective creates an alias for the physical directory path.

Additionally, any filename supplied in the request is treated as a CGI script, and the server attempts to run the script.

Syntax:ScriptAlias alias “physical_directory_path”

Context:Server config, virtual host

For example, the following directive can be used to process a request such as www.

nitec.com/cgi-bin/somescript.pl. The server tries to run somescript.plif proper permission is verified. Note that the ScriptAliasdirectory is not browseable:

ScriptAlias /cgi-bin/ “/www/nitec/public/cgi-bin/”

ScriptAliasMatch

The ScriptAliasMatchdirective is equivalent to the ScriptAliasdirective except that it uses regular expression, which allows you to define a dynamic alias rule instead of a fixed alias.

Syntax: ScriptAliasMatch regex directory Context:Server config, virtual host

For example, the following two directives do exactly the same thing:

ScriptAliasMatch ^/cgi-bin(.*) “/www/nitec/public/cgi-bin$1”

ScriptAlias /cgi-bin/ “/www/nitec/public/cgi-bin/”

Dans le document Apache Server2 Apache Server2 (Page 176-179)