homepage Welcome to WebmasterWorld Guest from 54.211.219.178
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Need help with Mod rewrite code.
compose




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

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

 

jdMorgan




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

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

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved