1

我一直在使用 .htaccess 将任何以特定目录开头的路径重定向到子域时遇到问题。主要问题可能是该目录实际存在,因为它是我的子域所指向的。我不关心维护路径,重定向到每个主页都可以。对于几个特定的​​域,我也需要这个,即:

website.com/foo -> foo.website.com
website.com/foo/about.html -> foo.website.com
website.com/foo/other/index.html -> foo.website.com

website.com/bar -> foo.website.com
website.com/foo/about.html -> foo.website.com
website.com/foo/other/index.html -> foo.website.com
4

2 回答 2

2

看起来您想要将Redirect特定文件夹转移到特定主机。作为使用的替代方法,mod_rewrite您可以使用mod_aliasRedirectMatch.

RedirectMatch ^/foo[$/]? http://foo.website.com/
RedirectMatch ^/bar[$/]? http://foo.website.com/

您当然可以添加更多规则以适应您的设置。

于 2013-09-26T14:17:29.043 回答
0

启用mod_rewrite.htaccess通过httpd.conf然后将此代码放入您的 DOCUMENT_ROOT/.htaccess文件中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^foo\. [NC]
RewriteRule ^(foo|bar)(/.*)?$ http://foo.%{HTTP_HOST}/ [L,R=301,NC]
于 2013-09-26T13:50:30.337 回答