【发布时间】:2018-10-22 15:55:11
【问题描述】:
因此,我们尝试将旧的子域重定向到我们的新域,并保持 URL 的其余部分不变。我们正在尝试将其全部移至子目录。
使用以下方法很容易...
RewriteCond %{HTTP_HOST} ^test\.example\.com/$ [NC]
RewriteRule ^(.*)$ https://example.com/test-path/$1 [R=302,L]
但是,之前的一些网站 URL 实际上已经是 test.example.com/test-path/,所以我们希望这些 URL 不会在 /test-path/ 上加倍
该规则正在将 URL 变成这样...
test.example.com/test-path/some-page
进入
test.example.com/test-path/test-path/some-page
所以现在我们正在尝试以下...
RewriteCond %{REQUEST_URI} !/test-path/
RewriteCond %{HTTP_HOST} ^test\.example\.com/$ [NC]
RewriteRule ^(.*)$ https://example.com/test-path/$1 [R=302,L]
虽然这将重定向到 example.com/test-path/,但它现在正在丢失正常 URL 之后的任何内容。
test.example.com/test-path/other-path
被重定向到
example.com/test-path/
希望这对我们正在尝试做的事情有意义。将子域重定向到新域到子目录中,而不是加倍 request-url 目录。
编辑:
通过最近的尝试,它似乎根本不在乎 url 是否包含 /test-path/。无论如何它仍然会重定向。
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite