سؤال

I have a project where users can create their own profiles. And the profiles will have sub-domain URLs like robert.blogger.com. So if that user has some domain of his own like robert.com. Then I want every request for robert.com to redirect to robert.blogger.com without changing the URL.

The URL should show robert.com/home.html, robert.com/aboutus.html etc. but actually code should be run from robert.blogger.com/index.html, robert.com/aboutus.html etc.

Is this possible? If so, how can this be done?

هل كانت مفيدة؟

المحلول 4

This will work

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domainname.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domainname.com
RewriteRule ^(.*) user/user.php?username=%1
ErrorDocument 404 /notfound.php
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

نصائح أخرى

This is not done with php.

The best way to accomplish this is via an HTACCESS redirect. Alternatively this can be done via a DNS A record, but would require elevated access.

place a file named (.htaccess) in the root directory of the domain that contains the following:

RewriteEngine On
RewriteRule * subdomain.domain.com [L]

Not possible in php unless you use curl. You need to setup a wildcard DNS record to catch all subdomains and send them to you web server. Then you need to setup Apache to catch all named virtual hosts and send it to a directory.

I would just the header function. header("Location: http://"$user_name."blogger.com");

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top