Jump to content

Looking for a more elegant or efficient way to


The14thGOD

Recommended Posts

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

Link to comment
Share on other sites

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

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.