我已經看過一些其他.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/..)
我需要做些什麼才能使其工作這樣子文件夾不會添加到路徑中?