รับทำเว็บไซต์ครบวงจร
เลือกภาษา Thai English     facebook
รายการหลัก



บทความ


Page Ranking Tool

Sub-Subdomains using Mod_rewrite and Wildcard DNS


สอน SEO
> Sub-Subdomains using Mod_rewrite and Wildcard DNS


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:



  Code
<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.



  Code
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.



  Code
<?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

refer: http://www.payingdialer.com/2006/06/sub-subdomains-using-modrewrite-and.html

Short URL click!
<< กลับคืน : เข้าชม 4,816 ครั้ง : ขึ้นไปด้านบน

รับทำเว็บไซต์ รับสร้างเว็บไซต์ รับออกแบบเว็บ รับเขียนเว็บ รับสอนทำเว็บ รับเช่า hosting รับเช่าพื้นที่เว็บไซต์ จดชื่อเว็บ รับโปรโมทเว็บไซต์ รับดูแลเว็บ SiteMap
สปริงเกอร์http://www.xn--22c2c4blb9n.xn--o3cw4h/