Welcome to WebmasterWorld Guest from 107.20.20.39

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Need help with Mod rewrite code.

   
5:13 pm on Aug 18, 2006 (gmt 0)

5+ Year Member



Hello,

I am new in writing mod_rewrite code. Please have a view on my code.

My current URL is -
1) http://mysite.com/bookinfo.php?book=abc

I want it to rewrite it into http://mysite.com/bookinfo/abc

for achiving this i wrote this rule in .htaccess

RewriteRule ^bookinfo/([^/]+)/?$ /bookinfo.php?book=$2 [L]

2)http://mysite.com/books.php?category=abc
I want rewrite it into
http://mysite.com/books/category/abc/

for achiving this i wrote this rule in .htaccess
RewriteRule ^books/([^/]+)/([^/]+)/?$ /books.php?$1=$2 [L]

Means final .htaccess code is -

RewriteEngine On
RewriteRule ^bookinfo/([^/]+)/?$ /bookinfo.php?book=$2 [L]
RewriteRule ^books/([^/]+)/([^/]+)/?$ /books.php?$1=$2 [L]

Please suggest me is my .htaccess file is okay for my purpose or it hase erors.

Warm regards,
Vineet

6:02 pm on Aug 18, 2006 (gmt 0)

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



The first rule should back-reference $1, not $2, Because $1 is undefined in the pattern.

Jim