I have a new web site that needs to 301 old pages and also add vanity url on some path
new website product page example url http://www.mywebsite.com/en/section/nice-url-name_123.html from this url i need to grab the section, name and id
this is my rule
RewriteRule ^en/([^_]+)/([^_]+)_([0-9]+).html /en/$1/detail.php?name=$2&id=$3 [L]
this works fine
on previous version of the website they used this url format
http://www.mywebsite.com/en/section/nice-url-name
I can't find a way to intercept this url and redirect to my new URL, id is missing and can be 0
so it should become http://www.mywebsite.com/en/section/nice-url-name_0.html
since i could't find a way i try adding a trailling slash at URL
RewriteCond %{REQUEST_URI} !\.(php|html?|jpg|png|gif|ttf|ttf)$
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
and then try to catch them section by section
RewriteRule ^en/section1/([^_]+)/ /it/301.php?redirectd=section1&name=$1 [L]
I couldn't find any other way without ending in infinite 301 loop But this way I need to exclude all my extension otherwise Apache will add trailing slash at the end of image, font, pdf and so on
To answer your statement "I can't find a way to intercept this url ..." I would like to suggest something along these lines:
RewriteEngine on
RewriteRule ^/?en/([^/]+)/([^\./]+)$ /en/301.php?redirected=1§ion=$1&name=$2 [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.