4

I have never been able to figure out how to do this.

I am working on a PHP script. With my script, each user will have access to their own site.

For example, the URL for this would be myscript.com/frontend/username where this uses an htaccess file to generate their site based on the username in the URL. (hope this makes sense).

Now I want to make it so that they can have their domain point to this.

For example, lets say their domain name is theirsite.com.

I want to make it so that, say if someone visits theirsite.com/about it really points to myscript.com/frontend/username/about

More examples:

  • theirsite.com/about should point to myscript.com/frontend/username/about

  • theirsite.com/blog/post-12 should point to myscript.com/frontend/username/blog/post-12

  • theirsite.com should point to myscript.com/frontend/username

How do I do this?

  • 1
    I understand what you are trying to do. I just don't understand why. Why are you recreating the wheel? What is wrong with multi-hosting the way it was designed to work? If you need a control panel, that is easy to take care of. What am I missing? What problem are you trying to resolve that I am not seeing? That may help us to address your question. – closetnoc Mar 27 '14 at 3:45
  • 1
    @closetnoc: What do you mean by "multi-hosting"? – MrWhite Mar 27 '14 at 11:45
  • Hosting more than one site on a server. Hence the multi. ;-) The reason why I asked the question was because the goal was not exactly clear. It seems like existing product will do the same thing. In fact, it seems your answer addresses my point. – closetnoc Mar 27 '14 at 15:11
  • the reason for this is so that my users can instantly have access to their website with no additional setup fees or waiting required. – scarhand Mar 30 '14 at 1:41
2

You could set up theirsite.com as a parked domain on top of myscript.com. This initially allows theirsite.com to be an alias for myscript.com. You can then use mod_rewrite (in .htaccess) to internally rewrite to the real URL (similar to what you have done already). You can only rewrite to a URL on theirsite.com (not myscript.com), which shouldn't be a problem since one is an alias for the other - unless there is something in your script that relies on the domain being myscript.com?

So, something like the following in .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} =theirsite.com [NC]
RewriteRule ^(.*)$ /frontend/username/$1 [L]

Although you would probably skip this step and rewrite to the actual URL - which you are already doing. So this effectively replaces your current rewrite rule.

  • fantastic answer. exactly what i was looking for. – scarhand Mar 30 '14 at 1:42

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.