Apache .htaccess文件夹重定向规则

时间:2012-02-01 10:12:44

标签: apache .htaccess mod-rewrite rewrite

我需要知道如何在同一个.htaccess文件中创建以下规则:

  1. example.com/st重定向到example.com
  2. example.com/[ANY STRING]重定向到new-example.com/[ANY STRING]
  3. 问题是我需要按原样发送查询字符串。

1 个答案:

答案 0 :(得分:0)

您的问题不是很明确,但您可以在.htaccess文件中尝试此代码:

Options +FollowSymLinks -MultiViews
RewriteEngine on

# your first requirement
RewriteRule ^st/?$ / [L]

# your second requirement; it will also append existing query string
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://new-example.com%{REQUEST_URI} [L,R=301]