URL rewriting – WordPress style

Add this into your .htaccess file…

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

The first RewriteCond checks if the requested URL exists as a file on the filesystem. In mod_rewrite, -f refers to a file, while the bang is the “not” operator. Therefore, !-f means “if the request script filename does not exist as a file”.

If the first rewrite_cond succeeds (that is, the requested file wasn’t found), then Apache moves on to the next condition. The !-d directive means it the condition succeeds if the requested script does correspond to an existing directory on the server.

Finally, if both conditions succeed, the request is forwarded to the index.php file, as specified in the RewriteRule directive.

You can now access request POST data.