简体   繁体   English

重写规则更改URL结构

[英]Rewrite rule change the URL structure

I am trying to redirect my old pages to my new updated link structure pages because the old ones are now giving 404 我正在尝试将旧页面重定向到新的更新的链接结构页面,因为旧页面现在显示404

Old

domain.com/artist-some-name

New

domain.com/artist/some_name.html

Where the - and _ between some name is put there instead of a space So basically i want to replace the - seperator with the / which i can with 某些名称之间的-和_放在那里而不是空格,所以基本上我想用/替换-分隔符

RewriteRule ^artist-(.+)$ /artist/$1.html [R=301,L]

But i can't work out how i can change the some-name to some_name so it will redirect properly 但我不知道如何将“ some-name”更改为“ some_name”,因此它将正确重定向

EDIT RewriteRule ^artists-(.+)-(.+)$ /artist/$1_$2.html [R=301,L] RewriteRule ^artists-(.+)$ /artist/$1.html [R=301,L] 编辑RewriteRule ^ artists-(。+)-(。+)$ /artist/$1_$2.html [R = 301,L] RewriteRule ^ artists-(。+)$ /artist/$1.html [R = 301, L]

Seems like this works for both if spaces in url or not 似乎无论URL中是否包含空格都适用

RewriteRule ^ artist-(。+)-(。+)$ /artist/$1_$2.html [R = 301,L]

Give these a try: 试试看:

RewriteRule ^artist-([a-z]+)-([a-z]+)$ /artist/$1_$2.html [NC,R=301,L]
RewriteRule ^artist-([a-z]+)$ /artist/$1.html [NC,R=301,L]

You need to limit the wild cards so that only letters are included. 您需要限制通配符,以便仅包含字母。 If you need to include numbers ('digits' in regex), then you can add 0-9 just next to the az . 如果需要包括数字(正则表达式中的“数字”),则可以在az旁边添加0-9 Alternatively, you can use \\d+ , for short. 另外,您也可以使用\\d+

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

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