I’m using mod_rewrite in my .htaccess to change a double directory structure into a double GET query string like so:
URL: http://domain.com/test/me/
After mod_rewrite: http://domain.com/index.php?u=test&c=me
using the following code in my .htaccess file:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?u=$1&c=$2 [L]
That works great, but if a second directory is not specified (e.g. http://domain.com/test/) I want the c variable to equal “all” like so:
http://domain.com/index.php?u=test&c=all
How can I do this? Thanks, regex looks like klingon poetry to me. I’ve tried a few different variations of the above code with no success.
P.S. bonus points if you can add a trailing / even if one is not typed into the url box, so that http://domain.com/test/me is handled the same as http://domain.com/test/me/ and http://domain.com/test is treated the same as http://domain.com/test/
Like this?
Also did the bonus 😛