Mod Rewrite Subdomain ด้วย PHP with GET variable (ใช้งานได้จริง)


หน้าแรก SEO Mod Rewrite Subdomain ด้วย PHP with GET variable (ใช้งานได้จริง)
Question?
I'm trying to wrap my head around mod rewrite, but can't seem to figure this out.

Is there a way I could do the following?

User types in: http://wildcard.mydomain.com

Silently writes to:

http://mydomain.com/index.php?username=wildcard

======================================================

Answer
You must capture the first part of the domain in a RewriteCond and then use this in a RewriteRule. The additional RewriteConds are there to prevent www.mydomain.com and index.php being rewritten



  Code
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{HTTP_HOST} ^(.+?).mydomain.com$
RewriteRule .* /index.php?username=%1 [L]



But this is only a small part of the needed functionality. Additionally, you must setup DNS entries for all of your username.mydomain.com domain names or setup a wildcard DNS entry *.mydomain.com pointing to your host.

Otherwise, the client tries to contact jcraine.mydomain.com, for example, and doesn't find a DNS entry and complains.

If this is a virtual host, you must also add a ServerAlias for each of your usernames



  Code
ServerAlias jcraine.mydomain.com



or a wildcard catching all subdomains



  Code
ServerAlias *.mydomain.com




refer: http://stackoverflow.com/questions/15330716/mod-rewrite-subdomain-to-php-with-get-variable

ขึ้นไปด้านบน