在我的網站我有一個名爲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