如何通过.htaccess将所有请求重定向到www目录?

如何通过.htaccess将所有请求重定向到www目录?,.htaccess,redirect,.htaccess,Redirect,我正在尝试创建一个.htaccess,它将为子域“测试”重定向所有请求,如下所示: http://test.mydomain.com/something/something2 (1) 到 所以在浏览器的地址栏中仍然是地址(1) 我有Apache2.0 我试着写了两个小时,但仍然找不到正确的方法 谢谢 你会想要这样的东西: RewriteEngine On # Only redirect if we're on the subdomain and haven't red

我正在尝试创建一个.htaccess,它将为子域“测试”重定向所有请求,如下所示:

http://test.mydomain.com/something/something2             (1)

所以在浏览器的地址栏中仍然是地址(1)

我有Apache2.0

我试着写了两个小时,但仍然找不到正确的方法


谢谢

你会想要这样的东西:

RewriteEngine On

# Only redirect if we're on the subdomain and haven't redirected
# (internally) to /www/ yet
RewriteCond %{HTTP_HOST}    ^test
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^.*$ /www/$0 [L]

# Let's also prevent them from being able to go to our /www path manually
RewriteCond %{THE_REQUEST}  ^(POST|GET)\s/www
RewriteRule ^www/?(.*)$ http://test.mydomain.com/$1 [R,L]

将apache虚拟主机中的文档根指向www是一个选项吗?不幸的是,我没有这个选项。
RewriteEngine On

# Only redirect if we're on the subdomain and haven't redirected
# (internally) to /www/ yet
RewriteCond %{HTTP_HOST}    ^test
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^.*$ /www/$0 [L]

# Let's also prevent them from being able to go to our /www path manually
RewriteCond %{THE_REQUEST}  ^(POST|GET)\s/www
RewriteRule ^www/?(.*)$ http://test.mydomain.com/$1 [R,L]