[英].htaccess 301 redirect subdomain and all files and folders to root
[英]htaccess 301 redirect root only but exclude all files and subfolders with exceptions
我不是.htaccess
代碼的程序員,我閱讀了其他相關帖子但不明白。 他們都不做我需要的。
I have a Wordpress site that runs on http://example.com/main
but want to redirect http://example.com
to http://otherexample.com/page.php
. 還需要不重定向http://example.com/anyfile
。
假設example.com
和otherexample.com
指向不同的地方,然后在example.com
的根.htaccess
文件中嘗試類似以下內容:
RedirectMatch 302 ^/$ http://otherexample.com/page.php
更新:我發現secondary.com 也被重定向。
如果您有多個域指向同一個地方,而您只想重定向其中一個域,那么您需要在重定向之前先使用 mod_rewrite 檢查主機名。
例如,下面的就需要去在頂部.htaccess
WordPress的前端控制器前文件:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^$ http://otherexample.com/page.php [R=302,L]
請注意, RewriteRule
模式匹配 URL-path 減去斜杠前綴,因此是正則表達式^$
(與RedirectMatch
指令不同)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.