helmsdeep Posted October 4, 2011 Share Posted October 4, 2011 Hello fine folks, Wondering if someone can help me with configuring apache/htaccess (xampp on windows, to be specific) to, if possible, perform the following url manipulations: Currently we are using parameterized query strings, such as website.com/discussion.php?topicid=35&pagenum=6&sort=ascending What we would like to do is replace the above with something like: website.com/discussions/why-are-grapefruits-round/ or, if unavoidable, website.com/discussions/why-are-grapefruits-round/page6/ which pulls the data from the old link. Maybe. I'm not sure how this works when you have multiple parameters, such as page #, sorting order, etc. The permalinks would not be dynamically created by users; they would be created by us (me) on an as-needed basis, similar to a blog. So, we do not need to configure apache to do all sorts of automated stuff -- I would expect to add the new permalink(s) manually as they emerge. Alternatively, we could just load the page in a frame and the url would appear static, but i'd prefer the real-deal. Thoughts/ideas? Thanks Quote Link to comment Share on other sites More sharing options...
requinix Posted October 4, 2011 Share Posted October 4, 2011 Luckily for you I've been generous all day today. Low on good karma. /discussions/why-are-grapefruits-round-35/page-6/sort-ascending RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule discussions/[^/]+-(\d+)(/page-(\d+)|/sort-(ascending|descending))* discussion.php?topicid=$1&pagenum=$3&sort=$4 [L,NC] The topicids will allow you to do this URL scheme for any topic you want, not just the ones you hand-pick. Without that ID the only thing you can use to identify a topic is the title, which means that has to be unique. Which they often aren't. Quote Link to comment Share on other sites More sharing options...
helmsdeep Posted October 6, 2011 Author Share Posted October 6, 2011 This seems to be helpful, but how can we handle the following 2 situations: 1) Some parameters (like sort order) are currently optional, and if not supplied I imagine this might break the rewriterule regex. Does this require some inflexibility, such that ALL possible parameters must be specified in some form, and in a particular sequence? Eg. /discussions/why-are-grapefruits-round-35/page-0/sort-default/items-per-page-5/background-color-green/hide-comments-true/...... 2) If I want to add new parameters later down the road, I suppose I can append them to the end of the path, as its probably not wise to restructure a path format that people and search engines have become familiar with. Still, it poses the same problem as above, in that we may end up with very long parameter-filled URLs. thanks again me Quote Link to comment Share on other sites More sharing options...
requinix Posted October 6, 2011 Share Posted October 6, 2011 1. The page and sort are already optional and don't have to be in that order. The URL I gave was just an example of what it could look like. /discussions/title-of-topic-123/option-value/option-value/option-value/... 2. Include new parameters in the (page|sort): RewriteRule # 1 2 3 4 5 discussions/[^/]+-(\d+)(/page-(\d+)|/items-per-page-(\d+)|/sort-(ascending|descending))* discussion.php?topicid=$1&pagenum=$3&perpage=$4&sort=$5 [L,NC] (Line breaks and comment only for readability. Don't keep them.) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.