Pergunta

Can anyone help me on htaccess pattern redirection ? The problem is as follows:

I have dynamic urls like http://somesite.com/house/name-name-name-12345 or http://somesite.com/house/name-12345 . I mean the URL pattern in house name - houseid. and the house name is concatenated with "-". Like if the name is "some house name" then the name is like some-house-name.

Now I have to 301 redirect through .htaccess file like

http://somesite.com/house/name-name-name-12345 => http://somesite.com/house/12345

or

http://somesite.com/house/name-name-12345 => http://somesite.com/house/12345

or

http://somesite.com/house/name-12345 => http://somesite.com/house/12345

for every dynamic urls. So how can I get that ?

Tried (from comment) :

RewriteCond %{THE_REQUEST} \ /house/(.*)-(.*)
RewriteRule ^ /house/%2
Foi útil?

Solução

Try this :

RewriteRule ^house/(.+)-([0-9]+)$ http://somesite.com/house/$2 [L,R=301]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top