I am trying to produce a rule utilized in b .htaccess file to complement not a specific string, within this situation: index.

I figured that it ought to be easy to match this special string first and employ [L] but that is no longer working,
and it ought to be possible while using following regex, however it leads to a 500 error.

I wish to match:

  • pagename1
  • pagename2/whatever
  • pagename3/234/whatever
  • about
  • contact-us
  • (etc)

although not

  • index/123
  • index/124/whatever

(BTW "index" may be the title of the file without any extension, not my choice, this can be a work factor)

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

I suppose that apache's implementation of regex does not deal with the (?!xxx) rule.

Any help/suggestions is going to be much appreciated.

You should use RewriteConds to get this done, for instance:

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

Which will rewrite every URL which does not begin by index. If you would like it to prevent it any place in the URL, take away the ^

(Please browse the comments. I doubt it and I have never experienced problems, although it gives one considerably cleaner .htaccess files, but: using RewriteCond might be preferred over using RewriteRule having a dash, because of how rulesets are processed?)

Only use RewriteRule the following, to not rewrite (the dash), and prevent subsequent spinning (the [L]) for something that begins with index/:

# Don't rewrite something that begins with index/

RewriteRule ^index/ - [L]

Following this, inflict spinning you want.

And maybe even limit more first:

# Don't rewrite files, sites or symbolic links

RewriteCond % -f [OR]

RewriteCond % -d [OR]

RewriteCond % -l

RewriteRule . - [L]

Apache used three different regular expression implementations. The very first was System V8, since Apache 1.3 they used POSIX ERE and also, since Apache 2 they will use PCRE. And just PCRE supports look-ahead statements. Which means you need Apache 2 to make use of that rule.

However for your question. If you are using this rule:

RewriteRule ^index/ - [L]

something that begins with /index/ ought to be catched with this rule with no further rule ought to be applied.

But when that does not work, do this:

RewriteRule !^index/ …

Again, this rule is going to be put on any request that’s URL path doesn’t begin with /index/.

And when you need to capture everything from the URL, make use of a RewriteCond condition to check either the entire URL path itself (%{REQUEST_URI}) or simply the match of your pattern groups:

RewriteCond %{REQUEST_URI} !^/index/
RewriteRule (.*) …
# or
RewriteCond $1 !^index$
RewriteRule ^([^/]+)/(.*) …