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
https://forums.phpfreaks.com/topic/248444-permalinks-htaccess-and-related/
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.

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.