Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite scenario

         

whoo

8:08 pm on Aug 8, 2007 (gmt 0)

10+ Year Member



I have a rather complicated setup that for some reason I am interested in mucking up, so let's see if this can be done.

Currently I have the following *pertinent* mod_rewrite rules:


RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=35]
RewriteRule ^page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L]
RewriteRule ^comments/page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L]
RewriteRule ^search/(.+)/page/?([0-9]{1,})/?$ /index.php?s=$1&paged=$2 [QSA,L]
RewriteRule ^search/(.+)/?$ /index.php?s=$1 [QSA,L]
RewriteRule ^archives/category/(.+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&paged=$2 [QSA,L]
RewriteRule ^archives/category/(.+)/?$ /index.php?category_name=$1 [QSA,L]
RewriteRule ^archives/author/([^/]+)/page/?([0-9]{1,})/?$ /index.php?author_name=$1&paged=$2 [QSA,L]
RewriteRule ^archives/author/([^/]+)/?$ /index.php?author_name=$1 [QSA,L]
RewriteRule ^archives/([0-9]{4})/page/?([0-9]{1,})/?$ /index.php?year=$1&paged=$2 [QSA,L]
RewriteRule ^archives/([0-9]{4})/?$ /index.php?year=$1 [QSA,L]
RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&paged=$3 [QSA,L]
RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2 [QSA,L]
RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&day=$3&paged=$4 [QSA,L]
RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3 [QSA,L]
RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&paged=$5 [QSA,L]
RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/?([0-9]+)?/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5 [QSA,L]

what I have been experimenting with is reversing the chronological display of items. I can do this successfully but doing so requires appending a query to the end of the url, ie,

this is an actual example of something that works:

http://www.domain.com/archives/category/bleh/?order=asc

My first goal would be to add another rule so that I could continue to maintain my cruft free urls, sans,

http://www.domain.com/archives/category/bleh/asc

This alone is simple enough, I assume, but along with the other thing I have going, not so simple.

I have a clickable paged navigation system in place and given the above url, the subsequent navigation system that WAS producing cruftless uris now outputs:

http://www.domain.com/archives/category/bleh/?order=asc&paged=2

since the rewrite rules no longer match, obviously.

Additionally, the potential for this type of URI exists:

http://www.domain.com/archives/category/bleh/page/2/?order=asc

which would be the result of someone changing the order AFTER having used the paged navigation. (the opposite of the example above)

I guess my starter question is this:

Is there a simple mod_rewrite solution to rewriting the 2 potential query options, so that my paged navigation system doesnt break, and so that I can continue to maintain my cruft free urls?

I apologize if this is confusing. :) Ive tried my best to explain.

jdMorgan

8:27 pm on Aug 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look very hard at the [QSA] flags on your existing rules. If a "static" or "friendly" URL is requested, is it really going to have a query string on it that you want to preserve after appending the new query info (the URL-path parameters to be passed to your script)?

After sorting all that, then it's simply a matter of making your rules recognize the (new) URLs defined by/on your pages and rewrite them properly to the script(s).

Also, be sure to completely flush your browser cache after any change to your rules. If a previously-cached URL is requested, your browser will serve it from cache, and no request will be sent to your server. In that case, your rewriterules cannot have any effect.

Jim

whoo

8:29 pm on Aug 8, 2007 (gmt 0)

10+ Year Member



OK, so youre saying then that the QSA flags are what's causing the paged=1 problem that i illustrate?

If not, Im lost. I'll be honest and say that I havent had to mentally deal with these rules for upwards of 2 years and mod_rewrite isnt my strong suit.

jdMorgan

8:32 pm on Aug 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're just asking about detecting/back-referencing incoming query strings, then you can do that with

RewriteCond %{QUERY_STRING} ^article=widgets&color=([a-z]{3,})$

followed by a rule for a URL-path with that query. In this example, the color could be back-referenced in the rule as "%1".

Jim

whoo

8:34 pm on Aug 8, 2007 (gmt 0)

10+ Year Member



way over my head -- I'll just leave it as is. :)