我试图将我的旧页面重定向到我的新更新的链接结构页面,因为旧的页面现在给出404
旧domain.com/artist-some-name
新domain.com/artist/some_name.html
在名字之间用-和_代替空格所以基本上我想用/替换-分隔符我可以用
RewriteRule ^artist-(.+)$ /artist/$1.html [R=301,L]
但是我不知道如何将some-name更改为some_name,以便它能够正确地重定向
编辑RewriteRule ^艺术家 -(.+)-(.+)$/艺术家/1 _ 2.美元html (R = 301 L)RewriteRule ^艺术家-(+)/艺术家/1.美元的html (R = 301 L)
似乎这对url中的if空格都有效
RewriteRule ^艺术家 -(.+)-(.+)$/艺术家/1 _ 2.美元html (R = 301 L)
试一试:
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]
您需要限制通配符,以便只包含字母。如果您需要包含数字(regex中的"数字"),那么您可以在a-z
旁边添加0-9
。您也可以使用'd+