在我的网站我有一个名为as.my
的目录,它实际上包含我网站上名为my.example.com
的子域的文件。如果有人访问www.example.com/as.my
,它们会显示子域。如果可能的话,我想要做的就是将以as.my
开头的任何URL重定向到子域,并从URL中去除as.my
。这可能吗?如何使用htaccess将现有目录重定向到子域?
我已经能够使用
Redirect Permanent /as.my http://my.example.com
的夹重定向,但如果有人访问http://www.example.com/as.my/test/
不正常工作。我也试图使用
RewriteRule ^as.my(/.*)$ http://my.example.com/$1 [L,NC,QSA,R=301]
但是,这也不能正常工作。有没有一种方法可以用来完成我正在尝试的? URL的行为如下:
http://www.example.com/as.my/ => http://my.example.com/
http://www.example.com/as.my/test/ => http://my.example.com/test/
谢谢任何帮助!
编辑:这是我的目录布局,以及每个内部的htaccess文件。
主目录包含example.com
的所有文件,以及目录as.my
,其中包含子域my.example.com
的所有文件。该htaccess
文件example.com
如下:
ErrorDocument 400 /pg.errors.php?eC=400
ErrorDocument 401 /pg.errors.php?eC=401
ErrorDocument 403 /pg.errors.php?eC=403
ErrorDocument 404 /pg.errors.php?eC=404
ErrorDocument 500 /pg.errors.php?eC=500
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
# Add WWW
RewriteCond %{HTTP_HOST} !^(my|www).
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
# Trailing Slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
# URL Rewrites (There are a few like this, but they're all the same)
RewriteRule ^about/$ about.php [L,NC,QSA]
RewriteRule ^contact/$ contact.php [L,NC,QSA]
</IfModule>
<Files .htaccess>
Order Allow,Deny
Deny From All
</Files>
的htaccess
文件中的as.my
目录如下:
ErrorDocument 400 /pg.errors.php?eC=400
ErrorDocument 401 /pg.errors.php?eC=401
ErrorDocument 403 /pg.errors.php?eC=403
ErrorDocument 404 /pg.errors.php?eC=404
ErrorDocument 500 /pg.errors.php?eC=500
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
# URL Rewrites (There are a few like this, but they're all the same)
RewriteRule ^help/$ help.php [L,NC,QSA]
</IfModule>
<Files .htaccess>
Order Allow,Deny
Deny From All
</Files>
<Files ~ "\.tpl$">
Order Allow,Deny
Deny From All
</Files>
'永久重定向HTTP /as.my:// my.example.com'? – 2014-10-03 16:43:32
@MarcB哎呀!这就是我之前的意图。我编辑了我的答案。 – 2014-10-03 16:48:37