[英].htaccess headache: redirect root folder to A, these folders to B, ignore the rest
該網站的結構是在根文件夾中包含主要語言 ( fi
),在子文件夾中包含其他語言版本。 該站點由真實文件夾中的 static HTML 文件組成,而不是虛擬文件夾。 在這里,我在第一行有一個有效的規則,並重定向所有針對這三個文件夾的流量。 但是,第二行並沒有做我想要的。
RedirectMatch permanent "(se|pl|en)\/(.+)?" https://www.example.com/example
RedirectMatch permanent "(!lv|!ee)\/?(.+)?" https://www.example.com/another-example
A
se
, pl
和en
需要重定向到 url B
lv
和ee
必須被忽略。如果我理解正確,您可以將這些規則與正則表達式錨點一起使用:
RewriteEngine On
# se|pl|en redirection
RewriteRule ^(se|pl|en) https://www.example.com/example/ [L,R=302,NC]
# anything other than /ee and /lv
RewriteRule !^(ee|lv)/ https://www.example.com/another-example/ [L,R=302,NC]
確保在測試這些更改之前清除瀏覽器緩存。
我忘記了RedirectMatch
並改用RewriteCond
+ RewriteRule
來開始工作。
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(se|pl|en)/
RewriteRule ^(.*)$ https://www.example.com/example/ [L,R=302]
RewriteCond %{REQUEST_URI} !/(ee|lv)/ [NC]
RewriteRule ^(.*)$ https://www.example.com/another-example/ [L,R=302]
從 anubhava 對這個問題的回答中應用: https://stackoverflow.com/a/21761345/1383913
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.