开发者

How can I add a global Apache rewrite rule?

Can I add global Apache rewrite rule, but not restrict the rule to a specific directory?

For example, add a rewrite rule applied both under 开发者_StackOverflow"/" and /news/.


Here you go:

  1. Do not execute the rule if the trailing word is a directory

    RewriteCond %{REQUEST_FILENAME} !-d

  2. Do not execute the rule if the directory (dir1 or dir3 or dir4) found in the URL

    RewriteCond %{REQUEST_FILENAME} [^(dir1|dir3|dir4)]

Again, you can test your rewrite rule here: http://martinmelin.se/rewrite-rule-tester/


Rewrite rules can be applied not only in <Directory> sections or .htaccess files, but also in the VirtualHost definition. They are even faster there because fewer jobs are needed.

You'll only get some problems if you want to play with the final file or directory name on the RewriteCond (as it's not yet decided), but you can sometime play with late filling of the conditions. Check for LA-U keyword in this documentation.

Now, this also means you cannot do that in a .htaccess as it's a configuration hook of a <Directory> section. Except for one thing; on a .htaccess ina subdirectory you can set the RewriteOptions inherit which means the rules of the parent directory are applied (so any rule set in the .htaccess or Directory section of the parent).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜