La regla de reescritura cambia la estructura de la URL

I am trying to redirect my old pages to my new updated link structure pages because the old ones are now giving 404

Viejo

domain.com/artist-some-name

Nuevo

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

EDIT 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

preguntado el 05 de mayo de 13 a las 21:05

2 Respuestas

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

contestado el 05 de mayo de 13 a las 21:05

Yeah but some of the artists only have one word therefor they links won't have any - or _ symbols as there is no spaces - Bren

I think it needs another rule for replacing every - con _ - Mi-Creatividad

Yeah not sure how to do that - Bren

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 a-z. Alternativamente, puede usar \d+, for short.

contestado el 06 de mayo de 13 a las 07:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.