开发者

How do I express this with a RewriteCond?

开发者 https://www.devze.com 2022-12-21 21:51 出处:网络
I want to redirect users to an error page if they enter any URL not starting with \'en\' or \'fr\'. I cannot figure out how to express this as a RewriteCo开发者_StackOverflow社区nd / RewriteRule.

I want to redirect users to an error page if they enter any URL not starting with 'en' or 'fr'. I cannot figure out how to express this as a RewriteCo开发者_StackOverflow社区nd / RewriteRule.

To be clearer, some examples:

http://mysite.com/en/foo/ ==> Cool, do nothing
http://mysite.com/fr/foo/ ==> Cool, do nothing

http://mysite.com/foo/ ==> ERROR, redirect to /404/index.php    
http://mysite.com/blah/foo/ ==> ERROR, redirect to /404/index.php

I'm sure it must be pretty simple but I could not find this specific scenario addressed. Thanks for your time.


^/(?!en|fr).*

This regex should match any path which doesn't begin with /en or /fr. The (?!expression) syntax is a negative lookahead; it matches a position where the contained expression doesn't start matching.

0

精彩评论

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