Forum Moderators: phranque

Message Too Old, No Replies

.htaccess not working

.htaccess not working?

         

smithydude

12:56 pm on Apr 17, 2009 (gmt 0)

10+ Year Member



Hello,

Would like to get the following URLs to rewrite to /find/productinfo.php?prodID=12 (or 20 or 60).

www.example.com/find/12/
www.example.com/find/20/
www.example.com/find/60/

I put the following rule in the .htaccess file in the "find" folder.

RewriteEngine on
RewriteRule ^find/([0-9][0-9])/$ /find/productinfo.php?prodID=$1

It's not working at the moment. Any tips?

Help much appreciated!

jdMorgan

1:09 pm on Apr 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The server will strip out the 'find/' part of the URL-path when passing control to /find/.htaccess -- The URL-path examined by RewriteRule is "localized" to the containing .htaccess file's location.

Therefore, "find/" should not appear in the RewriteRule's pattern in /find/.htaccess, it should only appear in the substitution.

You can shorten "[0-9][0-9]" to "[0-9]{2}" to match two digits only, to "[0-9]{1,3}" to match one to three digits, or to "[0-9]+" to match one or more digits.

For efficiency, always use an [L] flag unless you know you have a good reason not to.

Try:


RewriteRule ^([0-9]{2})/$ /find/productinfo.php?prodID=$1 [L]

Jim

smithydude

1:49 pm on Apr 17, 2009 (gmt 0)

10+ Year Member



YEEES! Thank you!

g1smd

2:25 pm on Apr 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Make sure that you link to the new URLs from within your site. It is links that 'define' URLs.

Next, make sure that anyone requesting a URL with

/find/productinfo.php?prodID=nnn
in it, is redirected to the new URL for that content, otherwise those old URLs could be indexed as Duplicates. This redirect should also force the correct domain name within the same redirect.