

RewriteRule / RewriteCond help - matches anything except a directory
source link: https://www.codesd.com/item/rewriterule-rewritecond-help-matches-anything-except-a-directory.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

RewriteRule / RewriteCond help - matches anything except a directory
Currently, I have the rule
RewriteRule ^([A-Za-z0-9-/]+)$ myFile.php?myId=$1
I want to be able to access a folder and its files (lets just say it's called example), and the index.php of it. However, using the rule
RewriteRule ^example$ example/index.php [L]
it instead matches the first rule. It is the first rule of the file, though.
After your rewrite rules are executed, the example
URL is rewritten to example/index.php
, and then re-enters the rewrite process (the [L]
flag does not prevent that). Then, your other rewrite rule matches.
So you must add an exception for example/index.php
. For example:
RewriteRule ^example/index.php$ - [L]
which terminates the second rewrite run. Make sure to insert it above your other rule.
Related Articles
How to match anything except a particular pattern after / before a specific string constant
How to match the exception with the double character with the regular expression of Python?
Javascript Regex matches everything except double space and then replaces
Define a regular JavaScript expression that matches anything but a particular string
Is there a way to match everything except a constant string using Go.Regexp?
Regex - matches everything except a specific string
PHP preg_match: matches anything but the string
regex is equivalent to something exactly but does not match anything else
RewriteRule with greedy matches trying to redirect the root to a page, and rewrite all other queries on https
Match everything except emails with this Regex pattern
Regex matches all except character groups
Matches everything except a specific model in JavaScript
Matches everything except for the specified strings
Using MATLAB for anything except mathematics
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK