Forum Moderators: phranque

Message Too Old, No Replies

Add custom variable into the request URI via .htaccess

Virtual hosting

         

Romano

12:45 pm on Mar 10, 2012 (gmt 0)

10+ Year Member



Hello Guys! I need to determine which a subdomain the user visited. For Log file all the paths is relative.

The Request => Apache Log file for domain.com (eg.)

domain.com/index.php => /index.php
sub1.domain.com/index.php => /index.php
sub2.domain.com/index.php => /index.php


May be via .htaccess I can do like for this example:

RewriteRule .* $0?HOST=%{SERVER_NAME} [QSA,L]


I have a shared hosting and I can't access to mod_log_config. Are there any solutions? Many thanks!

wilderness

2:03 pm on Mar 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a shared hosting and I can't access to mod_log_config. Are there any solutions? Many thanks!


I'm on an "el cheapo" shared host that offers up to five domains (others offer unlimited domains), and raw logs for each domain are available.

Is your situation the same with multiple domains?
OR
Do you have actual sub-domains (NO DNS) on a single domain?

Romano

2:20 pm on Mar 10, 2012 (gmt 0)

10+ Year Member



I have a single domain and its subdomains. Log file one at all.

wilderness

2:28 pm on Mar 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The only solution that I'm aware of is to sort the files after downloading.

You may be able to locate another host whom would (for a fee) a custom solution.

If your using PHP, you might inquire in the PHP Script forum.
PHP offers different capabilities than Apache/htaccess.

lucy24

8:51 pm on Mar 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



May be via .htaccess I can do like for this example:

RewriteRule .* $0?HOST=%{SERVER_NAME} [QSA,L]


I think this could work, but not in that form. You don't want SERVER_NAME; you want HTTP_HOST. And you don't need to monitor all requests, just the ones for pages; I assume images and css will always match the subdomain. This will shave many nanoseconds of server time. And, of course, you need to capture the original request and return it as %1.

Are you dealing with "real" subdomains, not just the with/without www. variation?

:: putting fingers in ears and humming loudly because I know what g1 is about to say ::

The htaccess would have to go in your top-level directory, the one shared by all your subdomains. That's assuming you have the typical setup where each subdomain lives in a separate physical directory inside the overall domain directory.

Interesting question. I may do some experimenting.

Romano

2:40 pm on Mar 13, 2012 (gmt 0)

10+ Year Member



I will try experimenting!

Other question, can I determine the status code for internal redirects in htaccess and use him with RewriteCond?