简体   繁体   中英

htaccess 301 redirect from old url to new url not working

I'm trying to redirect from old url to new url using below code.

RewriteEngine on

RewriteRule ^restaurantDetails.php?resid=(.+)&resname=(.+)$ /restaurant/$1/$2 [R=301,L]

But Its not working

or if I browse in address bar like below http://www.starmed.dk/restaurantDetails.php?resid=9&resname=demo-restaurant

then it will be redirect to http://www.starmed.dk/restaurant/9/demo-restaurant

Any idea how to do this with an HTACCESS 301 redirect?

You can use the following rule :

RewriteEngine on
RewriteCond %{THE_REQUEST} /restaurantDetails\.php\?resid=([^&]+)&resname=([^&\s]+) [NC]
RewriteRule ^ /restaurant/%1/%2? [NC,R=301,L]
RewriteRule ^restaurant/([^/]+)/([^/]+)/?$ /restaurantDetails\.php\?resid=$1&resname=$2 [NC,L]

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