Fedora 15

DocumentRoot /var/www/html

If you have a directory "universe" under /var/www/html, http://191.121.13.5/universe/flower1.jpg works fine. You don't need to create an alias.

However, if you want to access a file which is located outside the /var/www/html, you must create an alias.


example:

vi /etc/httpd/conf/httpd.conf

Alias /images /usr/images

Download several jpg files into /usr/images directory;

/sbin/service httpd restart

http://191.121.13.5/images/good/flower1.jpg

When Apache web server receives the URL request, it will retrieve the /usr/images/good/flower1.jpg file for the client.

Alias /images/ /usr/images/

For the definition (Alias /images/ /usr/images/) to work, Apache server is looking for /images/.

Explanation:

alias

The /images in http://191.121.13.5/universe/images/flower1.jpg will not activate the Alias matching process with the definition "Alias /images /usr/images".


ScriptAlias

The ScriptAlias directive is much like the Alias directive.

However, the ScriptAlias has the added meaning that everything under that URL prefix will be considered a CGI program.

ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/

With the above definition, if http://191.121.13.5/cgi-bin/test.pl is requested, Apache will execute the file /usr/local/apache2/cgi-bin/test.pl and return the output to the client.


Regex

Opening Square Bracket [, backslash \, caret ~, dollar $, period ., vertical |, uestion ?, asterisk *, plus + , opening round bracket (, closing round bracket ).

[ae] will match either a or e.

gr[ae]y will match either gray or grey.

^ matches at the start of the string, and $ matches at the end of the string.

^. matches a in abc.

The dot . matches a single character, except line break characters.

The full stop or period character (.) is known as dot. It is a wildcard that will match any character except a new line (\n). For example if I wanted to match the 'a' character followed by any two characters.

Text:    abc def ant cow  
Regex:   a..  
Matches: abc ant

$ matches at the end of the string.

.$ matches f in def.

? ---->0 or 1 of previous expression; also forces minimal matching   when an expression might match several strings within a search string. 
\ ---->Preceding one of the above, it makes it a literal instead of a special character.

Matching zero or more times with star (*)


AliasMatch

AliasMatch /images/(.*) /usr/images/$1

Both http://191.121.13.5/universe/images/flower2.jpg and http://191.121.13.5/images/flower2.jpg will return the same result.

Scenario 1:

1

Scenario 2:

2

 


AliasMatch ^/images/(.*) /usr/images/$1

The caret (^) matches the start of the string. The string is /universe/images/flower2.jpg.

3

4

5


AliasMatch can match patterns that Alias cannot accomplish.

AliasMatch ^/images/(.*)\.jpg$ /usr/images/jpg.image/$1.jpg

AliasMatch ^/images/(.*)\.gif$ /usr/images/jpg.image/$1.gif

6

7

$1 substitutes (.*)

The supplied regular expression is matched against the URL, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename.


ScriptAliasMatch

This directive is equivalent to ScriptAlias, but makes use of 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.

ScriptAliasMatch ^/?webmail/?$ /usr/local/cpanel/cgi-sys/wredirect.cgi

s1

ScriptAliasMatch ^/cgi-bin/(.*) /usr/local/apache/cgi-bin/$1

http://1ask2.com/cgi-bin/test.cgi

Apache will retrieve /usr/local/apache/cgi-bin/test.cgi.

$1 will be substituted with (.*).