rewrite help

New to mod_rewrite? This is a good place to start.

rewrite help

Postby lolbeans » Mon Jun 08, 2009 12:21 pm

Hi there, how would I rewrite something like:

/news?start=0, /news?start=1 etc to /news, /news/page-1 ?

I've got this so far:

RewriteRule ^news/([0-9]+)$ news?start=$1

But I'm sure that's incorrect.

Thanks for any help
lolbeans
 
Posts: 3
Joined: Mon Jun 08, 2009 12:17 pm

Postby richardk » Mon Jun 08, 2009 3:43 pm

You are missing page-
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteRule ^news$               /news?start=0  [QSA,L]
RewriteRule ^news/page-([0-9]+)$ /news?start=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby lolbeans » Tue Jun 09, 2009 1:33 am

Thanks that makes much more sense now. The only problem (which I thought I could get away with but apparently not!) is that I've also got the following rewrite rules in place: (which means it doesn't work :()

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


(It's for a cms that rewrites it to an alias you provide in your documents). However there is a news plugin that does pagination which doesn't really rewrite the urls.

I *think* the whole thing without any rewriting looks like this:

/index.php?q=2&start=2

The q=2 is the id of my news document, so it will always stay the same. The start=2 is the pagination bit.

Sorry for the long post, appreciate your help!
lolbeans
 
Posts: 3
Joined: Mon Jun 08, 2009 12:17 pm

Postby richardk » Tue Jun 09, 2009 3:40 pm

Try
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteRule ^(news)$               /index.php?q=$1&start=0  [QSA,L]
RewriteRule ^(news)/page-([0-9]+)$ /index.php?q=$1&start=$2 [QSA,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?q=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby lolbeans » Tue Jun 09, 2009 11:22 pm

Genius!

Thx :D
lolbeans
 
Posts: 3
Joined: Mon Jun 08, 2009 12:17 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: Google [Bot] and 119 guests

cron