Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 251773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:37:22+00:00 2026-05-11T21:37:22+00:00

I have two different domains that both point to my homepage in the same

  • 0

I have two different domains that both point to my homepage in the same server.

I want to log every single access made to my homepage and log which domain the user used to access my homepage, how can I do this?

I tried mod_rewrite in Apache and logging to a MySQL database with PHP but all I could do was infinite loops.

Any ideas?

EDIT:
By your answers, I see you didn’t get what I want…

As far as I know Google Analytics does not allow me to differentiate the domain being used if they both point to the same site and it also does not allow me to see that some files like images were accessed directly instead of through my webpages.

I can’t also just use $_SERVER[‘HTTP_HOST’] cause like I just said, I want to log EVERYTHING, like images and all other files, every single request, even if it doesn’t exist.

As for Webalizer, I never saw it differentiate between domains, it always assumes the default domain configure in the account and use that as root, it doesn’t even display it. I’ll have to check it again, but I’m not sure it will do what I want…

INFINITE LOOP:
The approach I tried involved rewriting the urls in Apche with a simple Rewrite rule pointing to a PHP script, the PHP script would log the entry into a MySQL database and the send the user back to the file with the header() function. Something like this:

.htaccess:

RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.net [NC]
RewriteRule ^(.*)$ http://www.domain1.net/logscript?a=$1 [NC,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.net [NC]
RewriteRule ^(.*)$ http://www.domain2.net/logscript?a=$1 [NC,L]

PHP Script:

$url = $_GET['a'];
$domain = $_SERVER['HTTP_HOST'];

// Code to log the entry into the MySQL database

header("Location: http://$domain/$url");
exit();

So, I access some file, point that file to the PHP script and the script will log and redirect to that file… However, when PHP redirects to that file, the htaccess rules will pick it up and redirect again too the PHP script, creating an infinite loop.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:37:22+00:00Added an answer on May 11, 2026 at 9:37 pm

    The best thing do would be to parse the server logs. Those will show the domain and request. Even most shared hosting accounts provide access to the logs.

    If you’re going to go the rewrite route, you could use RewriteCond to check the HTTP_REFERER value to see if the referer was a local link or not.

     RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.net [NC]
     RewriteCond %{HTTP_REFERER} !^(.*)domain1(.*)$ [NC]
     RewriteRule ^(.*)$ http://www.domain1.net/logscript?a=$1 [NC,L]
    
     RewriteCond %{HTTP_HOST} ^(.*)domain2\.net [NC]
     RewriteCond %{HTTP_REFERER} !^(.*)domain2(.*)$ [NC]
     RewriteRule ^(.*)$ http://www.domain2.net/logscript?a=$1 [NC,L]
    

    You may also want to post in the mod_rewrite forum. They have a whole section about handling domains.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two MVC3 sites, both hosted on the same server that I've configured
I have two different buttons on my page. I want them both to be
We have a Windows Server 2003 machine running IIS6.0 that hosts two different websites.
Because I have two websites on the same server and domain (different folders) and
I have two domains that are aliases, domain1.com and domain2.com Currently they are both
I have two webapps that will both be sitting on the same domain/tomcat application
imagine that I have two services with the same domain but different hostnames and
What's the best way to have two websites (asp.net based) running on different domains
i have two .net web application and they ara running on different domain same
I have two different libGL libraries on the same Ubuntu 11.04 machine. One library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.