我将子域(每个子域中有一个htaccess)重定向到一个新域,但我想将索引页重定向到新域上的子目录。
subdomain.example.com/index.php
至example.com/folder/index.php
subdomain.example.com
至example.com
我无法同时重定向。有办法吗?
答案 0 :(得分:0)
尝试将这些规则放在.htaccess文件中:
RewriteEngine on
Options +FollowSymlinks -MultiViews
# handles http redirect sub-dir
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{SERVER_PORT} =80
RewriteCond %{HTTP_HOST} ^(.+\.)?mysite\.com$ [NC]
RewriteRule ^/?(.*)$ http://www.anotheriste.com/feed?v=$1 [R=301,L,QSA,NE]
# handles http redirect non sub-dir
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{SERVER_PORT} =80
RewriteCond %{HTTP_HOST} ^(.+\.)?mysite\.com$ [NC]
RewriteRule ^/?(.*)$ http://www.anotheriste.com/$1 [R=301,L,QSA,NE]
# handles https redirect sub-dir
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{SERVER_PORT} =443
RewriteCond %{HTTP_HOST} ^(.+\.)?mysite\.com$ [NC]
RewriteRule ^/?(.*)$ https://www.anotheriste.com/feed?v=$1 [R=301,L,QSA,NE]
# handles https redirect non sub-dir
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{SERVER_PORT} =443
RewriteCond %{HTTP_HOST} ^(.+\.)?mysite\.com$ [NC]
RewriteRule ^/?(.*)$ https://www.anotheriste.com/$1 [R=301,L,QSA,NE]
R=301 will redirect with https status 301
L将制作最后一条规则
NE不用于转义查询字符串
QSA将附加您现有的查询参数
$ 1是你的REQUEST_URI