Forum Moderators: coopster

Message Too Old, No Replies

Help needed in preg replace to ake my mod rwrite rule correct

         

freak07

3:21 pm on Aug 21, 2010 (gmt 0)

10+ Year Member



I want to modrewrite my url to satic one i wrote the rule but its seems to be not working.Some experts saying that i need to do pregreplce function to make it work.As am a NooB in php. i dont know exactlyt what to do some body please help me

this is my rewrite rule
i want chnage my url site.co/load/index.php?id=1 
to site.co/load/index/1 and so on tht mean 1,50 etc
so that i put a rewrite rule
RewriteEngine On
RewriteBase /
RewriteRule ^load/index/([0-9]+)$ load/index.php?id=$1 [L]


but how do i do preg
_replace to change this code in my script
i want chnage my url site.co/load/index.php?id=1 
to site.co/load/index/1 and so on tht mean 1,50 etc
so that i put a rewrite rule
RewriteEngine On
RewriteBase /
RewriteRule ^load/index/([0-9]+)$ load/index.php?id=$1 [L]

Please help e to make it work

rocknbil

4:56 pm on Aug 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have it backwards (most common mistake in learning rewriting, IMO.)

What you do is put this in your pages

<a href="site.co/load/index/1">home</a>

Then your mod_rewrite does this

RewriteEngine On
RewriteRule ^load\/index\/(\d+)$ /load/index.php?id=$1 [L]

Note you don't need RewriteBase if you precede load with /. [0-9] is a synonym for \d.

The escapes (\/) in the pattern may not be necessary, habit of mine.


What you'll have to do in your scripts is

$this_id = 3456; // however you get a record id

echo "<a href=\"/load/index.php/$this_id\">$title</a>";

instead of

echo "<a href=\"/load/index.php?$this_id\">$title</a>";

freak07

10:33 am on Aug 22, 2010 (gmt 0)

10+ Year Member



so do i need to make it site.co/load/index etc site.co is y site its just a exapele i said

any way any many thanx for the replay i a NooB in php pls help me
i have this in my script this script is not done by me

ex = explode('/',$d['path']);
foreach($ex as $k=>$v)
{
if($v!='' and $v!='.' and $v!='..' and $v!=$setup['path'])
{
$s = mysql_fetch_array(mysql_query("SELECT `id`,`name` FROM `files` WHERE `path` LIKE '%".clean($v)."/' AND `size` = '0'"));
$s['name'] = str_replace('*','',$s['name']);
if($k >= sizeof($ex)-2) $put .= $s['name'];
else $put .= '<a href="index.php?id='.$s['id'].'">'.$s['name'].'</a>&raquo;';