EDIT @mootinator has done awesome work with this. See his answer below.
Since I wasn’t clear in specifying my exact URI, it may still help people who are looking for something similar. My URI is more like: 9/Here-is-some-text/unwatch
…in which case you need mod_rewrite rules that look a little more like this:
RewriteEngine on
RewriteRule ^([0-9]+)/([a-zA-Z0-9_-]+)/?$ index.php?id=$1 [QSA,L]
RewriteRule ^([0-9]+)/([a-zA-Z0-9_-]+)/unwatch/?$ index.php?id=$1&unwatch=1 [QSA,L]
Pretty minor modification to @mootinator’s answer, but took me a few minutes to figure out on my own. May help someone save time on down the line.
I’m trying to do a mod_rewrite to pass in a GET parameter, a sort of boolean flag so that whenever someone goes to URI/unwatch, you can pull out &unwatch=1.
I’ve got this rule already:
RewriteRule ^(\d+)/* index.php?id=$1 [L]
I would like to have another rule that does something like this:
RewriteRule ^(\d+)/unwatch index.php?id=$1&unwatch=1 [L]
The “directory” ./unwatch is not a directory at all. The directory structure looks like:
./index.php
./.htaccess
Any thoughts on how to do this?
QSA stands for Query string append. This way parameters passed by the user don’t get erased.
If there’s something I’m missing involving getting around the url not being an actual directory, check out how CakePHP does it.
Working demo here using the following .htaccess:
Turns out the space I had in [QSA, L] was causing the 500 error, and \d wasn’t behaving as I expected.