Jump to content

Permalinks, htaccess, and related


helmsdeep

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.