[英]htaccess for subdomain to the main domain
我們正在嘗試為我們的網站創建.htaccess重定向,這是我們想要做的:
我們的域名: http : //freewebsites.com
我們希望將所有訪問http://freewebsites.com/username的用戶重定向到http://username.freewebsites.com/
這應該適合任何訪問該網站的人。 因此,我們不需要索引文件之類的東西。
最好的方法是將PHP與GET變量一起使用
創建一個名為index.php的頁面並將此代碼放入其中
<?php
// check to see if Variable 'Username' is sent to it
if(isset($_GET["Username"])){
// if sent set User var
$user = $_GET["Username"];
//Send user to domain
header("Location: http://$user.freewebsites.com");
}else{
// if not send back to main domain
header("Location: http://freewebsites.com");
}
?>
如果您將用戶發送到URL,則使用此
http://freewebsites.com/index.php?Username=TestUser
將發送到
http://TestUser.freewebsites.com
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.