Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache mod_rewrite: explain me %{HTTP_HOST} especially when using addon domains

Apache mod_rewrite: explain me %{HTTP_HOST} expecially when using addon domains

Situation (directories tree) on an Apache server with addon domains:

main-domain.com/ 
| 
|_ .htaccess (just an empty file, no rule in here) 
|_ index.html (shown when accessing http://main-domain.com)
| 
|_ addon-domain-1.com/ 
|  | 
|  |_ .htaccess 
|  |_ index.html (shown when accessing http://addon-domain-1.com or http://main-domain.com/addon-domain-1.com/)
| 
|_ addon-domain-2.com/ 
   | 
   |_ .htaccess 
   |_ index.html (shown when accessing http://addon-domain-2.com or http://main-domain.com/addon-domain-2.com/)

Let's say in "addon-domain-1.com/.htaccess" file I have some rule using %{HTTP_HOST} like:

RewriteCond %{HTTP_HOST} ^something$

Does %{HTTP_HOST} evaluates to the domain of the currently requested url on server???

So if asking for:

http://addon-domain-1.com/

%{HTTP_HOST} will be "addon-domain-1.com"?

http://addon-domain-1.com (without final slash)

%{HTTP_HOST} will still be "addon-domain-1.com"?

http://www.addon-domain-1.com

%{HTTP_HOST} will still be "www.addon-domain-1.com"?

And when asking for:

http://main-domain.com/addon-domain-1.com

%{HTTP_HOST} will be "main-domain.com"???
or "main-domain.com/addon-domain-1.com"???
like image 739
Marco Demaio Avatar asked Jul 14 '10 18:07

Marco Demaio


People also ask

What is %{ HTTP_HOST?

The HTTP_HOST is obtained from the HTTP request header and this is what the client actually used as "target host" of the request. The SERVER_NAME is defined in server config.

Does HTTP_HOST include www?

The HTTP_HOST server variable contains www.mysite.com . The SERVER_PORT server variable contains 80 . The SERVER_PORT_SECURE server variable contains 0 and HTTPS contains OFF . The REQUEST_URI server variable contains /content/default.

What is mod_rewrite used for?

mod_rewrite provides a flexible and powerful way to manipulate URLs using an unlimited number of rules. Each rule can have an unlimited number of attached rule conditions, to allow you to rewrite URL based on server variables, environment variables, HTTP headers, or time stamps.

What is $1 in Apache RewriteRule?

$1 represents the match from the first set of parentheses in the RewriteRule regex, not in the RewriteCond regex.


2 Answers

You pretty much guessed them all right! The last one would be;

main-domain.com
like image 133
TheDeadMedic Avatar answered Sep 27 '22 22:09

TheDeadMedic


%{HTTP_*} evaluates to the HTTP header with the name given after the prefix shown. In HTTP 1.1, the host being accessed is given in the Host header, so yes.

like image 37
Ignacio Vazquez-Abrams Avatar answered Sep 27 '22 22:09

Ignacio Vazquez-Abrams