如何在.htaccess中执行以下操作?

时间:2016-01-03 08:50:09

标签: php apache .htaccess

我需要重写

  1. site.com/blog.php?blogger=somebody to somebody.site.com
  2. site.com/blog.php?blogger=somebody&content=sth&page=nxt to somebody.site.com/sth/nxt
  3. 使用.htaccess

1 个答案:

答案 0 :(得分:1)

试试这个:

RewriteCond %{HTTP_HOST} ^site.com$
RewriteCond %{REQUEST_URI} ^/blog.php$
RewriteCond %{QUERY_STRING} ^blogger=(.*)$
RewriteRule .* http://%1.site.com [L,R=301]

RewriteCond %{HTTP_HOST} ^site.com$
RewriteCond %{REQUEST_URI} ^/blog.php$
RewriteCond %{QUERY_STRING} ^blogger=(.*)&content=(.*)&page=(.*)$
RewriteRule .* http://%1.site.com/%2/%3 [L,R=301]