Noob need modrewrite help

Discuss practical ways rearrange URLs using mod_rewrite.

Noob need modrewrite help

Postby nightwalker » Sat Sep 05, 2009 10:47 am

hi,

ive hit a rut n need sum help ive followed sum of the examples given and at first appear to work but when switching through the pagination tings go tits up.

my index has aswitch in it heres exampl of it.

Code: Select all
switch ($mode) {
   
   case "gallery":
   //--------------- display product image gallery ---------------/
     include('assets/pages/gallery.php');
   break;
   case "productlist":
   //--------------- display product list ---------------/
     include('assets/pages/products.php');
   break;
   case "basicinfo":
   //--------------- display general product ino ---------------/
     include('assets/pages/basicinfo.php');
   break;      
   case "detailedinfo":
   //--------------- display advance product info& options ---------------/
     include('assets/pages/detailedinfo.php');
   break;      

}


Gallery example
atpresent a gallery example would be
mydomain.com/main.php?mode=gallery&id=xx&page=yy

i would like this to idealy be
mydomain.com/gallery/xx/yy

where xx is the id of the gallery and yy is the pag no.
product example
similarly if its products
mydomain.com/main.php?mode=products&page=yy

i would like this to idealy be
mydomain.com/products/yy where yy is the page no.

not sure where i was coming unstuk but the method i tried whorked for the first page but if u clicked page 2 or more thats when it would mess up and the address in the status bar would be mydomain.com/products/products/yy

thankyou for the time you take to get me out of this black hole, i really appreciate it.

regards

nightwalker
nightwalker
 
Posts: 1
Joined: Sat Sep 05, 2009 6:18 am

Postby richardk » Sun Sep 06, 2009 3:20 pm

Your problem is relative paths. FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^gallery/([0-9]+)/([0-9]+)/?$ /main.php?mode=gallery&id=$1&page=$2 [QSA,L]
RewriteRule ^products/([0-9]+)/?$         /main.php?mode=products&page=$1      [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 22 guests

cron