poe Posted January 31, 2012 Share Posted January 31, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256137-mod-rewrite-with-without-page-number/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.