2

I have 2 domains each going to the same IP address. Would it be possible to have the website recognise which domain is connecting to it and show a certain page accordingly?

It is only a small personal server, xampp is being used

  • @RoryDurrant XAMPP isn't a "web server". It is an easy to install package (or distribution), suitable for testing/developing, that includes Apache, MySQL and PHP. So, you are using the Apache web server. – MrWhite Nov 14 '16 at 23:01
2

Yes, you can do this. Assuming you are using Apache then you can do something like the following using mod_rewrite in either the server config or per-directory .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteRule ^/?foo$ /bar [R=302,L]

This will redirect http://www.example.com/foo to http://www.example.com/bar, but it will not do anything with the other domain.

The HTTP_HOST server variable holds the name of the host through which the site has been accessed.

Note also that this is 302 (temporary) redirect. (Temporary redirects should not be cached by the browser so can make testing easier.)

  • The reason is was unmarked was due to the fact it didn't actually work for me :/ – Rory Durrant Nov 15 '16 at 8:08
  • So what is it you are trying to do exactly? Do you get an error? What happens? In what way does it not work? – MrWhite Nov 15 '16 at 8:22
  • Trying to have multiple domains, connect to a same server but with different websites – Rory Durrant Nov 15 '16 at 8:25
  • And just nothing happened, all sorted now tho, thanks for the help – Rory Durrant Nov 15 '16 at 8:25
  • Ok, glad you got it sorted. (Although your question would seem to be about redirection, not configuring the server for multiple websites - your question implies that part is already done.) – MrWhite Nov 15 '16 at 8:30
1

Virtual Hosts:

<VirtualHost *>
ServerAdmin admin@localhost.com
DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
ServerName localhost
ServerAlias localhost
<Directory "C:/xampp/htdocs">
    Options Indexes FollowSymLinks Includes ExecCGI
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

Thanks for all the help though

  • 1
    This doesn't answer your question? If this is intended to provide more information to your question then please add this to your question, rather than adding an "answer". (Although this doesn't add any more information either.) – MrWhite Nov 15 '16 at 8:25
  • @w3dk I think it does answer his question. If you ignore that he used the word "redirect" and read it as "how do I direct a domain to the correct page content for that domain", virtual hosts is the best way to do it. Based on his comments on your answer, it sounds like he doesn't actually want to redirect anything. – Stephen Ostermiller Nov 15 '16 at 11:05
  • I have edited his question based on his comments to better illustrate what he really means – Stephen Ostermiller Nov 15 '16 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.