Jump to content

mod rewrite with & without page number


poe

Recommended Posts

i am trying to do a rewrite on 2 different types of urls..

 

the first configuration can be 1 of 3 ways...

 

http://localhost/site/index.php?type=top&pg=2
http://localhost/site/index.php?type=new&pg=3
http://localhost/site/index.php?type=fav&pg=1 etc...

 

i want to rewrite so it shows as

 

http://localhost/site/top/2/
http://localhost/site/new/3/
http://localhost/site/fav/

 

notice how the third sample (pg 1) doesnt need to show fav/1/ in the url, but instead show as /fav/

 

 

so far i have :

 

RewriteEngine On

RewriteRule ^top/([a-zA-Z0-9]+)[/]?(.*)$ index.php?type=top&pg=$1
RewriteRule ^new/([a-zA-Z0-9]+)[/]?(.*)$ index.php?type=new&pg=$1
RewriteRule ^fav/([a-zA-Z0-9]+)[/]?(.*)$ index.php?type=fav&pg=$1

 

... but i am missing how i can leave off the last part of the url if it is page 1

 

 

 

the second configuration is similar to the first except it is done by an infinite number of categories, which i would like to avoid listing each rule out seperatley per category.

 

the url will look like this...

 

http://localhost/site/index.php?cat=apparel&pg=2
http://localhost/site/index.php?cat=toys&pg=1
http://localhost/site/index.php?cat=footwear&pg=6
etc.... (can have unlimited number of categories)

 

 

and again my goal is to have the url look like :

 

http://localhost/site/apparel/2/
http://localhost/site/toys/
http://localhost/site/footwear/6/

 

and just like the first configuration, if on page 1, i wish to leave the pg out of the url.

 

so far i am trying to work with something like this :

 

RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)[/]?(.*)$ index.php?cat=$1&pg=$2

 

it fails when i try a url with no page defined (page 1)

 

thanks

chris

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.