The14thGOD Posted June 24, 2009 Share Posted June 24, 2009 I'm new to this mod_rewrite thing so I am just messing around trying to get it to work. I managed to get it to work but there's a problem with relative paths. I wanted to create something that could be very dynamic (meaning I can just drop this anywhere and it'll work with unlimited number of /paths/to/a/document/like/this vs /this/path/). Now, short of using absolute links to the files, this is what I came up with: <?php $thispage = explode('/',substr($_SERVER['PHP_SELF'],0,-4)); $fulluri = explode('/',$_SERVER['REQUEST_URI']); $num = sizeof($fulluri) - sizeof($thispage); for($i=0;$i<$num;$i++){ $pathback.= '../'; }?> The above $pathback is then used in code like: <?php $hash["$row[sub_category]"][]= "<a href=\"".$pathback."image_details.php?id=$row[id]\"><img class=\"galleryimg\" src=\"".$pathback.$row['thumbnail']."\" $dims alt=\"$row[title] thumbnail\" title=\"$row[title]\" /></a> \n"; ?> I'm trying to get into the habit of using more efficient code but when in unfamiliar territory that doesn't usually work. Anyone got any ideas or suggestions to make this work better? Also, sorry for doing this but I've been waiting in response and it's sort of relative to this anyways: From: http://www.phpfreaks.com/forums/index.php/topic,257882.0.html ... i have it to the point where it rewrites the url but if an invalid url is put in it's not redirecting to the right file: RewriteEngine On RewriteRule ^gallery/category/([a-z]+)/ gallery.php?category=$1 RewriteRule ^gallery/category$ ../../../index.php I think it ignores the ../ cause it's still going to the same page [404page] as if they were not there... Any help would be greatly appreciated. Justin Quote Link to comment Share on other sites More sharing options...
flyhoney Posted June 24, 2009 Share Posted June 24, 2009 I'm going to be annoying and suggest that you learn an MVC framework. Individually rewriting urls can be nasty. MVC frameworks offer a nice way to decouple your web pages from their urls. Some good PHP MVC frameworks: Kohana, CodeIgniter, Symfony, CakePHP Quote Link to comment Share on other sites More sharing options...
aggrav8d Posted June 24, 2009 Share Posted June 24, 2009 Why do you need to use relative paths? /image_details.php would work in your case and be less work than ../../../../../image_details.php. Quote Link to comment 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.