PHP और Htaccess का उपयोग करके गतिशील उप डोमेन बनाएँ
(1) मूल ।htaccess
इस फ़ाइल में पुनर्निर्देशन है http://www.yourwebsite.com को http://yourwebsite.com मुख पृष्ठ उपयोग के लिए। सबडोमेन पुनर्निर्देशन के लिए yourwebsite_folder
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourwebsite.com
RewriteRule (.*) http://yourwebsite.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^yourwebsite\.com $
RewriteCond %{REQUEST_URI} !^/yourwebsite_folder/
RewriteRule (.*) /yourwebsite_folder/$1
RewriteCond %{HTTP_HOST} ^(^.*)\.yourwebsite.com
RewriteCond %{REQUEST_URI} !^/yourwebsite_folder/
RewriteRule (.*) /yourwebsite_folder/$1
(२) फोल्डर के अंदर ।htaccess
यह फ़ाइल उपडोमेन यूआरएल को फिर से लिख रही है।
http://yourwebsite.com/index.php?siteName=9lessons
से
http://9lessons.yourwebsite.com
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([aA-zZ])$ index.php?siteName=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.yourwebsite.com
RewriteRule (.*) index.php?siteName=%1
अधिक .htaccess टिप्स: Htaccess फाइल ट्यूटोरियल और टिप्स।
index.php
इस फ़ाइल में सरल PHP कोड है, जो उप डोमेन मूल्य को मान्य करने वाले नियमित अभिव्यक्तियों का उपयोग करता है।
<?php
$siteName='';
if($_GET['siteName'] )
{
$sitePostName=$_GET['siteName'];
$siteNameCheck = preg_match('~^[A-Za-z0-9_]{3,20}$~i', $sitePostName);
if($siteNameCheck)
{
//Do something. Eg: Connect database and validate the siteName.
}
else
{
header("Location: http://yourwebsite.com/404.php");
}
}
?>
//HTML Code
<!DOCTYPE html>
<html>
<head>
<title>Project Title</title>
</head>
<body>
<?php if($siteNameCheck) { ?>
//Home Page
<?php } else { ?>
//Redirect to Subdomain Page.
<?php } ?>
</body>
</html>
कोई उपडोमेन फ़ोल्डर नहीं
यदि आप रूट निर्देशिका (htdocs / public_html) का उपयोग प्रोजेक्ट निर्देशिका के रूप में कर रहे हैं, तो इस .htaccess फ़ाइल का उपयोग करें।
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourwebsite.com
RewriteRule (.*) http://yourwebsite.com/$1 [R=301,L]
RewriteRule ^([aA-zZ])$ index.php?siteName=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.yourwebsite.com
RewriteRule (.*) index.php?siteName=%1