Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a web site / app where each user as a profile i.e.:
mydomain.com/user1
mydomain.com/user2
mydomain.com/user3
etc

How do I allow it so that a user can use their own domain name to go to their profile as a rewrite not a redirect. So when they go to lets say:
user1theirdomain.com they see there profile at mydomain.com/user1, but I don't want a redirect, I want it so their domain is seen in the address bar.

I imagine the user will need to adjust there domain name DNS to point to my server, what are the correct procedures and what would I need to do from there?

Also I wouldn't want to manually adjust things, I'd like it so when they point their domain to my server, my app will check the domain name, lookup the domain in my database and then serve the correct content.

Any ideas?

share|improve this question

migrated from stackoverflow.com Aug 7 '10 at 16:21

This question came from our site for professional and enthusiast programmers.

2  
that's entirely a serverfault question. both DNS ans web-server settings covered there. While you don't actually need a rewrite. there is nothing to rewrite as user already requesting your server –  Col. Shrapnel Aug 7 '10 at 12:41

3 Answers 3

up vote 0 down vote accepted

why not just use virtual hosts? As long as DNS is setup correctly so that theirdomain.com, or more specifically, user1.theirdomain.com, lands on your server, you can point the request to anywhere you need on the filesystem.

share|improve this answer

The easiest way to do this is with a 0-pixel frame. Basically, setup an IP address that people point their domain to, like 1.2.3.4. On 1.2.3.4, have a frameset like this:

<html>
<frameset rows="0,100%">
  <frame noresize frameborder=0 marginheight=1 scrolling=no src="/blank_page.html" />
  <frame noresize frameborder=0 marginheight=1 scrolling=no src="http://mydomain.com/userfoo" />
</frameset>
</html>

This could make some of your javascript more tricky...

share|improve this answer

On the PHP side of things you'd just need a $user = user_domain($_SERVER["HTTP_HOST"]) mapping. However, your webserver needs to accept random vhosts if your users are just to 'point' to your server. So if you are on shared hosting, there's no way to set this up.

Why aren't user subdomains sufficient? That would just need a RewriteCond %{HTTP_HOST} (.+) and RewriteRule .+ user.php?domain=$1. And it's likewise easier to set this up for your users (as redirect though).

share|improve this answer
    
SERVER_NAME will never help and subdomains do not need any rewrite. and user supplied domain is widely used, as a personal blog using some blog-hosting for example –  Col. Shrapnel Aug 7 '10 at 15:22
    
@CS: Most hosters allow to designate a catch-all target dir. Any %{SERVER_NAME} can easily be evaluated in .htaccess and PHPs $_SERVER. Subdomains don't necessitate separate subdirectories. –  mario Aug 7 '10 at 15:26
    
Ah I see, better use HTTP_HOST, not SERVER_NAME. (but depends on the actual webserver) –  mario Aug 7 '10 at 15:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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