Page 1 of 1

PHP/ Apache: URL rewrite

Posted: Tue Dec 08, 2009 7:21 pm
by lauthiamkok
Hi,
How can I rewrite the URL from this,
mysite.com/index.php?pg=news&current_page=1

to,
mysite.com/news?page=1


I have tried with this, but it doesnt work - something I have missed or it is written wrong completely?

RewriteEngine on

Code: Select all

RewriteRule 
^news?page=([a-zA-Z0-9\-]+)/?$  index.php?pg=news&current_page=$1 [QSA]
Thanks if you know how to correct it...

Cheers,
Lau

Re: PHP/ Apache: URL rewrite

Posted: Tue Dec 08, 2009 7:45 pm
by requinix
Make your index.php use page= instead of current_page=, then

Code: Select all

RewriteRule ^/?news index.php?pg=news [L,QSA]
The QSA means the page=1 will carry across to the rewritten URL.

By the way, a common solution to using a page number is something like /news/1. Then

Code: Select all

RewriteRule ^/?news(/(\d+))? index.php?pg=news&page=$2 [L]

Re: PHP/ Apache: URL rewrite

Posted: Tue Dec 08, 2009 8:41 pm
by lauthiamkok
tasairis wrote:Make your index.php use page= instead of current_page=, then

Code: Select all

RewriteRule ^/?news index.php?pg=news [L,QSA]
The QSA means the page=1 will carry across to the rewritten URL.

By the way, a common solution to using a page number is something like /news/1. Then

Code: Select all

RewriteRule ^/?news(/(\d+))? index.php?pg=news&page=$2 [L]
thank you. i works now when i use page=
thanks :D