简体   繁体   中英

htaccess redirect from old url to new friendly url not working

i've working on a ecommerce website, and on the landing page there are several products which user can see, if a user wants to see more details about a particular product he has to click on it which will then take him to viewproduct.php?productname=fidget-spinner&code=12345&id=12345

what i want is when a user clicks on a product URL should be this : viewproduct.php/productname/fidgetspinner/code/12345/id/12345

I am able to create a seo friendly url using htaccess but i have to go to viewproduct.php?productname=fidget-spinner&code=12345&id=12345 and then manually in the url i have to type the friendly url which works fine..i want seo friendly user to be displayed when a user clicks on viewproduct.php

any new suggestions would be appreciated!!

NEW FRIENDLY SEO URL :

Options +FollowSymLinks
RewriteEngine on
RewriteRule www.example.com/productname/(.*)/code/(.*)/id/(.*)$ viewproduct.php?productname=$1&code=$2&id=$3

this is what i've tried until now to redirect to new url when a user clicks on a product :

#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^www.example.com/productname/([a-z0-9]+)/code/([0-9]+)/id/([a-z0-9-]+)?$ viewproduct.php?productname=$1&code=$2&id=$3 

try this

//Redirect old file path to new file path//

Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM