简体   繁体   English

URL上的RewriteRule和301末尾没有斜杠

[英]RewriteRule and 301 on url without trailing slash at the end

I have a new web site that needs to 301 old pages and also add vanity url on some path 我有一个新的网站,需要301个旧页面,并在某些路径上添加虚荣网址

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 新网站产品页面示例url http://www.mywebsite.com/en/section/nice-url-name_123.html从此url我需要获取部分,名称和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 http://www.mywebsite.com/zh-CN/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 我找不到一种方法来拦截此URL并重定向到我的新URL,id丢失,并且可以为0

so it should become http://www.mywebsite.com/en/section/nice-url-name_0.html 因此它应该变成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 由于找不到方法,我尝试在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 没有找到无限的301循环结束,我找不到其他方法,但是这种方式我需要排除所有扩展名,否则Apache将在图像,字体,pdf等的末尾添加斜杠。

To answer your statement "I can't find a way to intercept this url ..." I would like to suggest something along these lines: 为了回答您的声明“我找不到一种方法来拦截此URL ...”,我想提出一些建议:

RewriteEngine on
RewriteRule ^/?en/([^/]+)/([^\./]+)$ /en/301.php?redirected=1&section=$1&name=$2 [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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