Here is another version for Wordpress, original one did not work as intended.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [END]
RewriteCond $1 ^(index\.php)?$ [OR]
RewriteCond $1 \.(gif|jpg|png|ico|css|js)$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [END]
RewriteRule ^ /index.php [L]
</IfModule>
# END WordPress
Reference from this Github repository, modified a bit. After excessive testing this rule does not solve all problems. We have a Wordpress webshop, which has 40 plugins and somewhere is there a rewrite clash. I sincerely hope next version of Wordpress has no URL rewrites.
RewriteRule ^index\.php$ - [L]

The ^
signifies start of the string, \
escapes .
or it would mean any character, and $
signifies end of the string.
^index\.php$
if http(s)://hostname/index.php -
do nothing [END]
flag can be used to terminate not only the current round of rewrite processing but prevent any subsequent rewrite processing.
RewriteCond $1 ^(index\.php)?$ [OR]

In RewriteCond
using $1
as a test string references to captured contents of everything from the start to the end of the url http(s)://hostname/bla/bla.php. If used in substitution or condition it references to captured backreference. RewriteRule (bla)/(ble\.php)$ -
for http(s)://hostname/bla/ble.php captures bla
into $1
and ble.php
into $2
. Multiple capture groups can be accessed via $3..N
.
( )
groups several characters into single unit, ?
forces the match optional.
[OR]
flag allows you to combine rewrite conditions with a logical OR relationship as opposed to the default AND.
In short, if bla/bla.php contains index.php OR next condition
RewriteCond $1 \.(gif|jpg|png|ico|css|js)$ [NC,OR]
( )
groups several characters into single unit, |
separates characters to subgroups and conditions them if any one of.
[NC]
flag causes the RewriteRule to be matched in case-insensitive manner.
In short, if bla/bla.php ends with any of the filetypes OR next condition
RewriteCond %{REQUEST_FILENAME} -f [OR]
Server-Variables are variables of the form %{ NAME_OF_VARIABLE } where NAME_OF_VARIABLE can be a string taken from the following list:

%{REQUEST_FILENAME}
is full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time REQUEST_FILENAME is referenced. Otherwise, such as when used in virtual host context, the same value as REQUEST_URI. Depending on the value of AcceptPathInfo, the server may have only used some leading components of the REQUEST_URI to map the request to a file.
-f
check for regular file. Treats the test string as pathname and tests whether or not it exists.
In short, if bla/bla.php is a file OR next condition
RewriteCond %{REQUEST_FILENAME} -d
-d
check for directory. Treats the test string as a pathname and tests whether or not it exists.
In short, if bla/bla.php is a directory
RewriteRule ^(.*)$ - [END] not as in Github [S=1]
This statement is only executed when one of the condition returned true.
.
match any character *
zero or more times.
The [S]
flag is used to skip rules that you don't want to run. The syntax of the skip flag is [S=N]
, where N
signifies the number of rules to skip (provided the RewriteRule matches). This can be thought of as a goto statement in your rewrite ruleset. In the following example, we only want to run the RewriteRule if the requested URI doesn't correspond with an actual file.
In short, do nothing
RewriteRule ^ /index.php [L]
The [L]
flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed. This corresponds to the last command in Perl, or the break command in C. Use this flag to indicate that the current rule should be applied immediately without considering further rules.
In short, rewrite every path as http(s)://hostname/index.php
I fetched this little doc together from apaches.org documentation. Links below.