的.htaccess重写正则表达式匹配任何条件,但"指数" [英] .htaccess rewrite regex: match anything but "index"

查看:123
本文介绍了的.htaccess重写正则表达式匹配任何条件,但"指数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个.htaccess文件用来匹配的什么,但一个规则一个特定的字符串,在这种情况下:首页

I'm trying to create a rule used in a .htaccess file to match anything but a particular string, in this case: index.

我认为这应该是可能的第一个匹配这个特殊的字符串,并使用 [L] 但是,这并不工作,
并使用以下正则表达式应该是可能的,但它会导致一500错误

I thought that it should be possible to match this special string first and use [L] but that's not working,
and it should be possible using the following regex, but it causes a 500 error.

我要匹配:

  • pagename1
  • pagename2 /不管
  • pagename3 / 234 /不管
  • 有关
  • 与美
  • (等)

而不是

  • 指数/ 123
  • 指数/ 124 /不管

(BTW指数是一个没有扩展名,不是我的选择的文件的名字,这是一个工作的事情)

(BTW "index" is the name of a file with no extension, not my choice, this is a work thing)

^(?!index)[\w/\-]+

我认为Apache的实现正则表达式不应对(?!XXX)规则。

任何帮助/建议,将大大AP preciated。

Any help/suggestions will be much appreciated.

推荐答案

您可以使用的RewriteCond s到做到这一点,例如:

You can use RewriteConds to do this, for example:

RewriteCond %{REQUEST_URI} !^index
RewriteRule (.*) index.php?what=$1

这将重写每一个不被索引启动URL。如果你想它的任何地方,以避免它在URL中删除 ^

That will rewrite every URL which doesn't start by index. If you want it to avoid it anywhere in the URL, remove the ^

这篇关于的.htaccess重写正则表达式匹配任何条件,但"指数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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