1
如何將Apache的前綴匹配轉換爲Nginx?轉換重寫規則前綴從Apache到Nginx的匹配
RewriteCond %{REQUEST_URI} ^/test1
RewriteRule ^(.*)$ http://newsite/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/foo
RewriteRule ^(.*)$ http://newsite/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/bar
RewriteRule ^(.*)$ http://newsite/$1 [R=301,L]
或者
RewriteRule ^/test1/(.*)$ http://newsite/test1/$1 [R=301,L]
RewriteRule ^/foo/(.*)$ http://newsite/foo/$1 [R=301,L]
RewriteRule ^/bar/(.*)$ http://newsite/bar/$1 [R=301,L]
是不是這樣呢?
location/{
rewrite ^/(test1|foo|bar)/(.*)$ http://newsite/$1/$2 permanent;
...
}
所以這也適用於'/ test1/aaaa'嗎? – Kokizzu
@Kokizzu - 正確。 'location/test1'是**前綴匹配**,並且將匹配'/ test1/aaaa'。此外,'$ request_uri'將包含doiman之後的所有內容(即'/ test/aaaa')。 – grochmal