I have four different types of rewrites I'm trying to do with multiple parameters in each.
First, the URLs with no modification:
http://www.example.com/index.php?p=/category/page-slug&pn=2/
http://www.example.com/index.php?p=/category/&f=feed/rss (feed, feed/, feed/rss, feed/atom are the only possible values for the f parameter)
http://www.example.com/index.php?p=tag&t=tag-one+tag-two+-tag-three&pn=2/
http://www.example.com/index.php?p=search&q=search+query+goes+here&pn=2/
Next, what I'd like to be able to type into the browser instead:
http://www.example.com/category/page-slug/2/
http://www.example.com/category/feed/rss
http://www.example.com/tags/tag-one+tag-two+-tag-three/2/
http://www.example.com/search/search+query+goes+here/2/
Finally, what I've tried, along with countless variations:
RewriteRule ^([a-zA-Z0-9-/+]+)([0-9]+)$ index.php?p=/$1&pn=$2/ [L]
RewriteRule ^([a-zA-Z0-9-/+]+)([a-zA-Z/]+)$ index.php?p=/$1&f=$2/ [L]
RewriteRule ^([a-zA-Z0-9-/+]+)([a-zA-Z/]+)([0-9]+)$ index.php?p=/$1&t=$2&pn=$3/ [L]
RewriteRule ^([a-zA-Z0-9-/+]+)([a-zA-Z/]+)([0-9]+)$ index.php?p=/$1&q=$2&pn=$3/ [L]
I'm able to handle just the p parameter fine using:
RewriteRule ^([a-zA-Z0-9-/+]+)$ index.php?p=/$1 [L]
However, everything else has completely escaped me. I feel like I'm close, but it's incredibly frustrating because I don't know of any way to narrow the problem down. It either works or it doesn't. Thanks in advance.
Best Answer
Here you go: (note that this strips the trailing "/" for
pn
variables)... and a PHP file to simplify testing:
Update: If you plan to have variable category names and you cannot guarantee that the
/
character will work as a separator, you should consider handling URI parsing within your application itself.Example rewrite directives:
Example PHP file: