开发者

Conditional Rewrite in Apache 2: are these two Identical?

开发者 https://www.devze.com 2023-02-22 01:52 出处:网络
Can ... RewriteCond %{REQUEST_URI} ^/folder1/ [OR] RewriteCond %{REQUEST_URI} ^/folder2/ [OR] RewriteCond %{REQUEST_URI} ^/folder3/

Can ...

RewriteCond %{REQUEST_URI} ^/folder1/ [OR]
RewriteCond %{REQUEST_URI} ^/folder2/ [OR]
RewriteCond %{REQUEST_URI} ^/folder3/
RewriteRule (.*) / [R=301,L]

... be rewritten to ...

RewriteCond %{REQUEST_URI} ^/(folder1|folder2|folder3开发者_如何学运维)/
RewriteRule (.*) / [R=301,L]

?

And if so, are they absolutey identical in functionality?

Suggestions/improvements are much appreciated.


They are the same thing, the | stands for OR so if it starts with /folder1/ or /folder2/ or /folder3/ do the redirect.

So yes it would be shorter and work out for your needs.

As Pekalski suggested you can make it shorter with:

^/folder[1-3]/

A few more examples and references can be found at: http://semlabs.co.uk/journal/mod_rewrite-quick-reference-and-cheat-sheet

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号