重写规则,如果条件不匹配 [英] Rewrite rule if condition is not matched

查看:231
本文介绍了重写规则,如果条件不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以执行规则,如果URL是不匹配的路径论坛

例如:


  

的RewriteCond如果URL不是论坛


  
  

重写规则(JS | GIF | CSS | JPG | PNG)!$
  %{DOCUMENT_ROOT}的index.php [L]



解决方案

Apache的<一个href=\"http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond\"><$c$c>RewriteCond以及在<一个href=\"http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond\"><$c$c>RewriteRule指令支持感叹号来指定一个非匹配模式:


  

您可以preFIX模式字符串
  一个 '!'字符(惊叹号)来
  指定非匹配模式。


这应该工作:

 的RewriteCond%{REQUEST_URI}!^ /论坛。*
!重写规则\\。(JS | GIF | CSS | JPG | PNG)$的index.php [L]

- >重定向所有请求不的论坛的而不是列出足够的index.php期末数期初数

How may I perform a rule if the url is NOT matching the path "forums"

For example:

RewriteCond IF URL IS NOT forums

RewriteRule !.(js|gif|css|jpg|png)$ %{DOCUMENT_ROOT}/index.php [L]

解决方案

Apache's RewriteCond as well as the RewriteRule directive support the exclamation mark to specify a non-matching pattern:

You can prefix the pattern string with a '!' character (exclamation mark) to specify a non-matching pattern.

This should work:

RewriteCond %{REQUEST_URI} !^/forums.*
RewriteRule !\.(js|gif|css|jpg|png)$ /index.php [L]

--> redirect all requests not beginning with forums and not ending with the listed suffices to index.php

这篇关于重写规则,如果条件不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆