簡體   English   中英

htaccess 301 僅重定向根目錄,但排除所有文件和子文件夾,但有例外

[英]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.comotherexample.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM