I want to rewrite some URL’s based only on the last parameter. For example:
http://www.site.com/some-param/some-param/THIS-param
I want to grab THIS-param and use that for the rewrite. It always be the last parameter, but not necessarily the 3rd. Could be 2nd, 3rd, 4th, or 5th.
Im getting close with this:
RewriteRule ([^/]+)$ index.php?url_title=$1 [NC,L,QSA]
using this as the url (for example).
http://www.test.com/param1
The problem is, once I add ‘param2’ the site stops working. I think it’s cause param1 appear to be a directory.
http://www.test.com/param1/param2
Any idea why? Here’s my full set of rules:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
RewriteRule ([^/]+)$ index.php?url_title=$1 [NC,L,QSA]
RewriteRule .* index.php [L]
You nearly had it. You need to capture everything that comes after the last
/, and optionally capture what comes before it if needed. You said it coudld be 2nd through 5th, but didn’t mention 1st, so that assumes something comes before it with a/, as in^.+/.This also allows for a trailing
/Edited to incorporate existing rules: