[英]301 redirect (.htaccess) of entire domain to another domain index
我試過自己解決這個問題,但我似乎無法弄清楚。
這是我正在嘗試做的事情:
將subdomain.example.com上的所有 URL(包括索引)創建 301 重定向到example.com 。
例如:
這意味着我不想保留在 subdomain.example.com 上使用的相同 URL 結構。 我只希望子域上的 URL 指向 example.com 上的索引。 我知道這不是 SEO 的最佳解決方案,但這就是我想要的。
我嘗試過使用
Redirect 301 / https://example.com/
但這保留了 URL 結構,我不希望這樣。
那么我該如何解決呢?
您無法通過Redirect
實現此目的,因為它將舊的 URL 路徑附加到新路徑。 您可以使用RewriteRule
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteRule (.*) https://example.com/ [R=301,L]
根據文檔https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect
保留 url 的一部分。
使用redirectMatch,您可以使用正則表達式和替換來重寫您的 url 例如
RedirectMatch 301 . https://example.com/
其中點 (.) 是匹配任何東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.