将文件重定向并重写到子域

时间:2011-11-21 01:26:57

标签: .htaccess redirect rewrite subdomain

我们的网站有这个网址

http://mydomain.com/blog.php?id=50

并需要将其重定向到

http://blogs.mydomain.com/blog.php?id=50

必须创建子域或文件夹,还是我们可以直接创建.htaccess文件?

1 个答案:

答案 0 :(得分:2)

在.htaccess文件中尝试以下内容

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC] 
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^blog\.php$ http://blogs.mydomain.com/blog.php?id=%1 [L,R=301]