.htaccess rewrite regex: match anything but “index”

后端 未结 3 1896
孤城傲影
孤城傲影 2021-02-20 00:31

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

I thought that it sho

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-20 00:56

    (Please read the comments. I doubt it and I've never encountered problems, while it gives one much cleaner .htaccess files, but: using RewriteCond might be preferred over using RewriteRule with a dash, due to how rulesets are processed?)

    Just use RewriteRule as follows, to not rewrite (the dash), and stop subsequent rewriting (the [L]) for anything that starts with index/:

    # Do not rewrite anything that starts with index/
    RewriteRule ^index/ - [L]

    After this, do any rewriting you like.

    Or maybe even limit some more first:

    # Do not rewrite files, directories or symbolic links 
    RewriteCond %{REQUEST_FILENAME} -f [OR] 
    RewriteCond %{REQUEST_FILENAME} -d [OR] 
    RewriteCond %{REQUEST_FILENAME} -l 
    RewriteRule . - [L]

提交回复
热议问题