我们正在尝试为我们的网站创建.htaccess重定向,这是我们想要做的事情:
我们的域名: http://freewebsites.com
我们希望将所有来到http://freewebsites.com/username的用户重定向到http://username.freewebsites.com/
这适用于任何访问该网站的人。所以,我们不需要索引文件或其他东西。
答案 0 :(得分:0)
最好的方法是使用带有GET变量的PHP
创建一个名为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