ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => หัวข้อเริ่มโดย: arttojung ใน 06 พฤศจิกายน 2011, 17:52:55

ชื่อเรื่อง: สร้างซับโดเมนด้วย php
โพสต์โดย: arttojung ใน 06 พฤศจิกายน 2011, 17:52:55
คือผมอยากรู้วิธีสร้างซับโดเมน โดยใช้สคริป php อะครับ คือผมหาอ่านมา 2-3 วันแล้วมันก็ยังทำไม่เป็นซักที ไม่ทราบว่าผมจะต้องเขียนประมาณไหนบ้างครับ
อยากได้แบบ กระทู้ http://www.thaiseoboard.com/index.php?topic=221648.0 อะครับไม่ทราบว่าจะพอมีใครรู้วิธีเขียนบ้างหรือป่าว
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: arttojung ใน 06 พฤศจิกายน 2011, 18:13:05
ดันหน่อยครับ เผื่อมีใครรู้
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: AKarnny ใน 06 พฤศจิกายน 2011, 18:17:38
อยากได้เหมือนกัน  :wanwan017:
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: kuznetsova ใน 06 พฤศจิกายน 2011, 18:20:24
โดยอ่านจากไหนนี่แหละครับ ใช้วิธี mod rewrite เข้าช่วย
แต่ผมยังไม่เคยลองทำตามนะ ไม่รู้เวิร์คป่าว  :wanwan023:
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: smapan ใน 06 พฤศจิกายน 2011, 18:26:06
In an internet-savvy world, subdomains can play a big role in user awareness. Descriptive subdomains are easy to remember, strengthen the credibility of a website and encourage a visitor to bookmark it.


Quick example:
a) http://tomcat.apache.org
b) http://www.jguru.com/faq/home.jsp?topic=Tomcat
Which one would you prefer?

Even better, subdomains and sub-subdomains can be pointed to dynamic content using Apache's mod_rewrite and Wildcard DNS entries.
Called: http://topic.domain.com
Served: http://www.domain.com/generator.php?topic  (invisible)
The visitor requests http://topic.domain.com  while the actual content is dynamically served by a PHP script in the background.

Requirements
To realize this on your server,
- a DNS server with support for wildcard DNS entries (eg. BIND) has to be available,
- this DNS server must be the authorative DNS server for your domain,
- Apache with mod_rewrite has to be installed.

Authorative Nameserver for your domain
This means that you need to setup a NS entry and point it to your Nameserver. The corresponding line for your zone file is

domain.com NS ns.domain.com
Add a Wildcard DNS record to your Nameserver
Wildcard DNS records match all requests for domain names without a record. You can set up a wildcard record to match all subdomains of your domain like this:

*.domain.com. A 1.2.3.4
where 1.2.3.4 is the public IP address of your webserver. Be sure to include the last dot in your FQDN.

Configure Apache Wildcard support
Assuming your Apache config uses vHosts, your new configuration would look like this:


<virtualhost>
ServerName domain.com:80
ServerAlias *.domain.com
...
..
</virtualhost>
The ServerAlias statement enables Wildcard support for your domain. From now on, your Apache vHost will react on non-existent subdomains.

Configure redirects using mod_rewrite
To activate proper subdomain redirects, save the text below, put it into a .htaccess file and upload it into the the http root directory of your domain.


RewriteEngine On
#prevents rewrite loops
RewriteCond %{REQUEST_URI} !^/generator.php?(.*)?$
# match the subdomain
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.domain\.com$ [NC]
# append the path
RewriteRule ^(.*)$ /generator.php?%2/$1 [QSA,L]
Test your redirect
This PHP code captures the name of your subdomain. You can save it and upload it as generator.php to test your subdomain setup.
<?php $server_host = explode('.', $_SERVER['HTTP_HOST']); $subdomain = strtolower($server_host[0]); echo 'Subdomain name is: ' . $subdomain; ?>
Visit an imaginary subdomain, eg. http://test223.domain.com .
If everything works, you'll see "test223" on your screen which is dynamically generated by generator.php.

Same setup for Sub-Subdomains
If you plan to use sub-subdomains instead, you can apply this guide with a couple of changes to an existing subdomain:
- Setup an authorative NS for your Subdomain (sub.domain.com NS ns.domain.com)
- Add a wildcard DNS record for your Subdomain (*.sub.domain.com. A 1.2.3.4)
- Add a Wildcard alias in the Apache vHost of your existing subdomain (ServerAlias *.sub.domain.com)
- Change the mod_rewrite code accordingly

เอามาจาก http://www.thaiseoboard.com/index.php/topic,13057
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: pokerthai ใน 06 พฤศจิกายน 2011, 18:26:52
อยากรู้เหมือนกันครับ
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: arttojung ใน 06 พฤศจิกายน 2011, 18:53:40
แฮะๆ มีภาษาไทยหรือป่าวครับ อ่านแล้ว งง นิดหน่อย :P
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: arttojung ใน 06 พฤศจิกายน 2011, 20:52:19
มีใครรู้วิธีทำบ้างครับ แบบท่านบนผมแอบ งง :P มีภาษาไทยหรือป่าวครับ
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: kokarat ใน 06 พฤศจิกายน 2011, 20:58:31
ทำได้ไม่ยากครับเดี๋ยว upload ให้ดูครับ
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: pokerthai ใน 06 พฤศจิกายน 2011, 20:59:15
อ้างถึงจาก: kokarat ใน 06 พฤศจิกายน 2011, 20:58:31
ทำได้ไม่ยากครับเดี๋ยว upload ให้ดูครับ


เจ๋งครับ+!
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: arttojung ใน 06 พฤศจิกายน 2011, 21:00:41
อ้างถึงจาก: kokarat ใน 06 พฤศจิกายน 2011, 20:58:31
ทำได้ไม่ยากครับเดี๋ยว upload ให้ดูครับ
ขอบคุณครับ
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: TummZ ใน 06 พฤศจิกายน 2011, 21:47:49
ขอบคุณด้วยครับ อยากทราบเหมือนกัน  :wanwan017:
ชื่อเรื่อง: Re: สร้างซับโดเมนด้วย php
โพสต์โดย: ioffer30 ใน 06 พฤศจิกายน 2011, 22:02:00
รอ ๆๆๆๆ อยากได้จะได้ไม่ต้องไปเพิ่มที่ cpanel