簡體   English   中英

htaccess 重定向和別名根文件夾

[英]htaccess redirect and alias root folder

我在 webroot 中有一個名為foo的文件夾,位於.com/foo/*/ 我正在嘗試做一些事情。 我希望可以通過.com/bar/*.com/bar/baz/*訪問文件夾foo的內容。 但是,我還想將流量從.com/foo/*重定向到.com/bar/* ,以便用戶遷移到新端點。 這個想法是不要在打開應用程序的情況下破壞當前用戶。

我有這些規則在分開時有效,但是當同時使用它們時,我只會得到一個重定向循環。 我相信事情應該更多地與適當的標志結合起來,但我似乎無法找出適當的組合。

RewriteRule ^foo/(.*)$ /bar/$1 [R=302,NC,L]

RewriteRule ^bar/baz/(.*)$ bar/$1 [QSA]
RewriteRule ^bar/(.*)$ foo/$1 [QSA]

編輯1:

.com/bar/.com/bar/baz/將在內部正確指向真實目錄foo

但是 '.com/bar and .com/bar/baz will not point correctly to the real directory foo`。 規則是可修復的還是強制使用斜杠會更好?

RewriteRule ^foo/(.*)$ /bar/$1 [R=307,NC,L]

RewriteRule ^bar/baz/(.*)$ foo/$1 [NC,END]
RewriteRule ^bar/(.*)$ foo/$1 [NC,END]

如果您使用的是 Apache 2.4+,那么您可以使用END

RewriteEngine On

RewriteRule ^foo/(.*)$ /bar/$1 [R=302,NC,L]

RewriteRule ^bar/baz/(.*)$ bar/$1 [NC,END]

RewriteRule ^bar/(.*)$ foo/$1 [NC,END]

如果您使用的是舊的 Apache 例如 2.2 等,請使用:

RewriteCond %{THE_REQUEST} \s/+foo/ [NC]
RewriteRule ^foo/(.*)$ /bar/$1 [R=302,NC,L]

RewriteRule ^bar/baz/(.*)$ bar/$1 [NC,L]

RewriteRule ^bar/(.*)$ foo/$1 [NC,L]

暫無
暫無

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

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