Forum Moderators: phranque

Message Too Old, No Replies

htaccess Redirect or Rewrite

Remove part of the URL

         

bestgoods

8:19 pm on Feb 20, 2011 (gmt 0)

10+ Year Member



We need to point another store to a new URL.

We have searched the forum and Google for 2 days and hope someone can help us.

How can we change take out the last part of the UR, such as in http://www.example.c...ct-p-1272.html?

We want to remove the "-p-1272" part. Or just all the way to the end by removing "-p-1272.html".

Note: the "-p-" is static and never changes but "1272" the number part is dynamic and changes from product to product.

So if a customer enters say http://www.example.c...uct-p-1588.html they will be directed to http://www.example.c...example-product or http://www.example.c...uct-p-1588.html (depending on how we set it up in .htaccess

Actually we need to direct the name only of the product (WITHOUT the 4 digit model number at the end of the existing URL) in our new store to a new product with a new model number. But do not want to lose the existing Google indexes.

Thank you in advance

g1smd

1:51 am on Feb 21, 2011 (gmt 0)

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



You need to alter the links on the page to advertise the right URLs. You do this by altering the PHP script that generates them.

To redirect users requesting old URLs, you'll likely need to make your own PHP script and rewrite all "old" URL requests to it. When called from an "old" URL, the script simply looks in the database for the details of the new URL that "matches" the old URL, and then sends back a 301 redirect response pointing to that new URL.

There is no way for .htaccess to "know" that /great-widgets.html maps to /widgets-p-2345.html nor can .htaccess alter the links that appear on your pages.