簡體   English   中英

.htaccess子目錄重寫異常

[英].htaccess Subdirectory Rewrite Exception

我目前正在整合我們最近收購的一個站點上的帖子,該站點上有多個WordPress安裝用於管理內容,一個安裝在public_html文件夾中,另一個安裝在子目錄中,如下所示:

1. http://domain.com/
2. http://domain.com/another-install/

我們將所有內容從/another-install/移至主設置,並使用301重定向從所有舊鏈接中刪除/another-install/ ,如下所示:

RedirectMatch 301 ^/another-install/(.*) http://domain.com/$1

結果所有文章都這樣重定向:

http://domain.com/another-install/article-name/
TO
http://domain.com/article-name/

問題是,我們要保持/another-install/作為頁面可見。 使用當前重定向, http://domain.com/another-install/轉到http://domain.com/ 有什么方法可以添加例外或重寫當前規則,以使其保持/another-install/可見?

將您的正則表達式從(.*) (與任何字符的0或多個匹配)更改為(.+) (與任何字符的1或多個匹配)。 這意味着在/another-install/之后必須要有一些東西才能進行重定向。

您需要一個RewriteRule來指定排除項。 將此添加到您的.htaccess文件

RewriteCond %{REQUEST_URI} !^/old-install/(index\.wml)?$ [NC]
RewriteRule ^old-install/(.+)$ http://domain.com/$1 [R=301,NC,L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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