我已经看过一些其他.htaccess的问题,但没有我的具体用例。.htaccess文件重定向子域的目录
形势
我有一个网站,说example.com。它有一个子域sub.example.com。网络主机还为每个子域提供一个文件夹:example.com/sub
我想将sub.example.com和example.com/sub链接到othersitem.com/some/folder/path/
我至今(代码还增加了WWW的事情,不要问为什么,除非能解决的事情):
在/.htaccess:
RewriteBase/
##Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
##301 Redirect Entire Directory
RedirectMatch 301 /sub/(.*) https://othersite.com/some/folder/path/$1
在/子
/.htaccess:
RewriteBase /sub/
##Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.example.com[nc]
RewriteRule ^(.*)$ http://www.sub.example.com/$1 [r=301,nc]
##301 Redirect Entire Directory
RedirectMatch 301 /(.*) https://othersite.com/some/folder/path/$1
的问题
当我使用sub.example.com/foo/bar
重定向作品(它重定向到https://othersite.com/some/folder/path/foo/bar
)
当我使用example.com/sub
它打破(它重定向到https://othersite.com/some/folder/path/sub/foo/bar
,注意../sub/..)
我需要做些什么才能使其工作这样子文件夹不会添加到路径中?