I’m trying to set-up an .htaccess file that will pass every request URL as GET into a file called index.php. The only exception is, when the request URL points to a directory res.
Examples:
/wiki/cool-stuff => index.php?uri=/wiki/cool-stuff
/wiki/cool-stuff?news=on => index.php?uri=/wiki/cool-stuff&news=on
/res/cool-photo.jpg => res/cool-photo.jpg
Two problems:
- The GET variable passed to
/wiki/cool-stuffin the second example is not passed to index.php - Accessing
/res(not/res/!!) suddenly shows me/res/?uri=resin my browser and index.php withuri=res/. Accessing/res/instead, shows me index.php withuri=res/and the URL in the browser stays (which is okay).
The .htaccess:
RewriteEngine on
RewriteBase /subthing/
RewriteCond %{REQUEST_URI} !/res/(.+)$
RewriteCond %{REQUEST_URI} !index.php
RewriteRule (.*) index.php?uri=$1
How can I achieve the desired behaviour?
Try using the Query-String-Append flag,
QSAMake the trailing slash optional – in Regex, this is achieved by adding
?.New
.htaccess:Note that I have tweaked the Regex on the
/resfolder to cause/resabcto be redirected (if the slash was the only optional piece, anything beginning withreswould match.Apache Mod_Rewrite Documentation