Katzumi
Katzumi

Reputation: 351

htaccess URL Rewrite for products doesn't redirect me

There is plenty of information out there but nothing I've read on the interwebz has given me an answer as to why my htaccess is not working.

I cannot determine why my rule isn't rewriting the URL as I thought it would. I have the following url:

domain.com/Book/bookpage/index.php?bookID=123&bookName=foo_bar

I would like to change it so that when someone hits that URL, it shows like:

domain.com/Book/123/foo_bar

I started off trying to get it to work using just the Book ID and haven't even gotten that to work.

This is what I have thus far:

RewriteRule ^Book/([0-9]+)$    /Book/bookpage/index.php?bookID=$2

However, after placing that htaccess in the root of the site and going to the URL:

domain.com/Book/bookpage/index.php?bookID=123

The URL in the address bar remains the same.

Upvotes: 2

Views: 124

Answers (2)

Book Of Zeus
Book Of Zeus

Reputation: 49877

try this:

RewriteEngine On
RewriteBase /

# this rewrite domain.com/Book/123 or domain.com/Book/123/
RewriteRule ^Book/([0-9]+)/?$ /Book/bookpage/index.php?bookID=$2 [L,NC,QSA]

# this rewrite domain.com/Book/123/title or domain.com/Book/123/title/
RewriteRule ^Book/([0-9]+)/([a-z0-9\-_]+)/?$ /Book/bookpage/index.php?bookID=$1&bookName=$2 [L,NC,QSA]

Upvotes: 2

fanfavorite
fanfavorite

Reputation: 5199

Try adding [L,R=301] at the end of the line:

RewriteRule ^Book/([0-9]+)$ /Book/bookpage/index.php?bookID=$2 [L,R=301]

Upvotes: 0

Related Questions