Forum Moderators: coopster
I am working on a custom forum now that uses $_GET['cateogry'] and the same with the id of the forum. Since this was done different ( the CMS used $_GET['category'], and exploded everything after that to get values into an array ), how do I take id=30 and turn that into /the-page-title.html ? Do you have to overwrite the values for $_GET['id'] or how does this work exactly?
Thanks for any help on the matter, have very little experience with this topic.
Options -MultiViews
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /
RewriteRule /(.*)/(.*)/(.*)/ cmsscript.php?pf=$1&pn=$2&action=$3
In this case
[mysite.com...]
can be re-written as
[mysite.com...]
No $_GET parameter is involved for the url encoding. Since the package is most likely unaware of the conversions, the decoder has to be implemented in the .htaccess with something similar to what posted above and another part inside the php script (cmsscript.php from above) that will re-populate the superglobals so everything will be transparent to the rest of the code.
Also, if you are on Apache 2.x, look into using AcceptPathInfo to pass your 'SEO-friendly virtual URLs' to your script.
If you use this method, then you can replace the '$_GET explode' routine with one that takes the variables directly from the URL-path. Then look up the category or item using its friendly URL as the database lookup key, instead of its 'id' number.
---
A note to techtheatre:
Your code will execute up to hundreds of times faster with a few simple changes:
Options -MultiViews +FollowSymLinks +Indexes
RewriteEngine on
#
RewriteRule /([^/]+)/([^/]+)/([^/+])/$ cmsscript.php?pf=$1&pn=$2&action=$3 [L]
You can interpret the new "([^/]+)" subpatterns in two equivalent ways, the second of which reveals why it's faster: It means "match one or more characters not a slash" and "match one or more characters until you find a slash, then stop." Compare this to "(.*)" which will initially match the entire requested URL-path, and then have to back off and re-try, one character at a time starting at the end of the requested URL-path, trying to leave just enough characters for the last, and then the next-to-last "(.*)" subpatterns to match. This is a *very* inefficient process when multiple "(.*)" subpatterns are used.
"RewriteBase /" is the default, and need not be specified unless there is a non-default RewriteBase preceding this one in the file. So I removed it.
(I don't want to hijack this thread. If further discussion is warranted, we can open a new thread. However, it is in the interest of the members here to stop the spread of inefficient code.)
Jim