Forum Moderators: phranque

Message Too Old, No Replies

Help need in modrewrite

modrewrite help

         

freak07

4:32 am on Aug 21, 2010 (gmt 0)

10+ Year Member



Hello am a noob in modrewrite. I tried to wrote the rule for a urls but its not working a here lookking for help plwease some body help me out.Modrewrite is turned on in my host and its working.but i cant able to modrewre my url
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 its not working please help.please soe one help me to do a working rule
but its not working please somebody help me

jdMorgan

12:25 pm on Aug 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code looks fine, as far as it goes.

How did you test this?

What were the results?

How did those results differ from what you expected?

If you got a server error, what was in your server error log file?

If you type "http://www.example.com/load/index/1" into your browser, you should see the page produced by your script located at filepath /load/index.php when passed a query string of "id=1".

As far as "changing the URLs that appear as link on your pages and in the browser address bar," that is not what mod_rewrite does. To change those URLs, you must edit your HTML or modify your script(s) and/or database(s) to publish the new 'friendly' URLs. The code above will then tell the server how to convert requests for those friendly URLs, when they arrive at your server, back into a properly-formatted call to your script(s).

[added] Basically, it may be that your understanding of what mod_rewrite does is incomplete, and that you have completed only one of two required steps -- or one of three recommended steps. See the thread Changing Dynamic URLs to Static URLs [webmasterworld.com] in our Apache Forum Library [webmasterworld.com] for more information. [/added]

Jim

freak07

2:45 pm on Aug 21, 2010 (gmt 0)

10+ Year Member



thanks jdMorgan i tried modifying in script but i dont tried in database coz that script was not made by me

freak07

2:57 pm on Aug 21, 2010 (gmt 0)

10+ Year Member



this is the sql qurey what should i do here?


$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;';

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



Use preg_replace to reformat the "link" to your friendly format after reading it in from the database.

This preg_replace function will essentially be the exact opposite of that of the RewriteRule that you just coded. More useful information may be available in our PHP forum.

Jim

freak07

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

10+ Year Member



ok jim thnx for reply but one help please can u gie a xaple of preg_replace in this code plss

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



Sorry, I am not a PHP coder. :(

Jim

freak07

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

10+ Year Member



oh soryy so what should i do :(

g1smd

8:49 pm on Aug 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Post a clear explanation and your best effort code in the WebmasterWorld PHP forum.