Welcome to WebmasterWorld Guest from 54.159.50.111

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

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

RewriteRule of directory

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

Full Member

10+ Year Member

joined:Jan 19, 2003
posts:324
votes: 0


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 :(

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

Senior Member

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

joined:Mar 15, 2002
posts:6807
votes: 0


Maybe there's an error on a previous line?
3:24 pm on Mar 22, 2003 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


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>

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

Full Member

10+ Year Member

joined:Jan 19, 2003
posts:324
votes: 0


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