Welcome to WebmasterWorld Guest from 54.145.44.134

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Help:mod_rewrite: /directory/ --> /page.php?id=directory does not work

RewriteRule of directory

     

iProgram

3:16 pm on Mar 22, 2003 (gmt 0)

10+ Year Member



I have successfully used .htaccess file to rewrite www.mysite.com/info-123.html to www.mysite.com/showinfo.php?id=123

Now I want to rewrite directory, for example:
www.mysite.com/sth/aaa/xyz-info-123.html to www.mysite.com/showinfo.php?dir=aaa&name=xyz&id=123

I use the following rewrite rule to make a test:

RewriteRule ^/NetTools$ /test.php?target=3
RewriteRule ^/NetTools/Messengers$ /test.php?target=34

or
RewriteRule /directory/([0-9]+) /dbase.php?id=$1

But it does not work at all :(

DrDoc

3:24 pm on Mar 22, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Maybe there's an error on a previous line?

jdMorgan

3:24 pm on Mar 22, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



iProgram,

In an .htaccess context, do not use a preceding slash on your patterns. Also, do not use an end anchor ($) unless you wish to rewrite only requests which have no trailing slash or further path info appended.


RewriteRule ^NetTools /test.php?target=3 [L]
RewriteRule ^NetTools/Messengers /test.php?target=34 [L]

or
RewriteRule directory/([0-9]+) /dbase.php?id=$1 [L]

Introduction to mod_rewrite [webmasterworld.com]

HTH,
Jim
<added>Also, use the [L] flag unless you have a good reason not to.</added>

iProgram

3:30 pm on Mar 22, 2003 (gmt 0)

10+ Year Member



Thank you jdMorgan. It works now:)
<Owner Edit>
Another useful link about this:
[phpfreaks.com...]