2015-05-14 95 views
0

我正在为我的问题寻找一个解决方案,我在我的PHP projet中有一定的结构MVC,如果我想要执行或显示一个页面,我的磁带上的URL为:mydomainname.com/index.php?do=agentmydomainname.com/index.php?do=property ...其中'agent'和'财产'是我的控制器。子域名和重写网址?

现在我想添加一个子域的每个人我都在数据库为例:johnydeep.mydomainname.com,而这个URL必须指向我的控制器,“代理”像如果我这样做:mydomainname.com/index.php?do=agent&name=johnydeep

莫非你告诉我,如果我应该需要重写我的网址(Apache的htaccess的),或者如果有任何其他方法,这有助于

感谢,

回答

0

您可以通过使用htaccess的URL重写很容易做到这一点。

RewriteEngine On 

# Parse the subdomain as a variable we can access in PHP, and 
# run the main index.php script 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{HTTP_HOST}  !^www 
RewriteCond %{HTTP_HOST}   ^([^\.]+)\.([^\.]+)\.([^\.]+)$ 
RewriteRule ^(.*)$ /$1?do=agent&name=%1 
+0

嗨感谢您回应,怎么样 “的RewriteCond%{REQUEST_FILENAME}!-f”,这是什么意思服务器和什么有关规则的“^(。*)/ $ 1吗?做=剂名称= %1“,你能解释我吗? – abderrahimbk