htaccess redirect urls to specific urls

113 views Asked by At

I have Old URLs in my site and it like this:

http://'www.example.com/newsroom/press-release/item/949-ItemAlias.html 

I want to redirect it to :

http://'www.example.com/press/ItemAlias.html

I used this sentence in .htaccess:

RewriteRule ^newsroom/press-release/item/(.*)$ /press/$1 [R=301,NC,L]

But this sentence redirect the URLs to http://'www.example.com/press/949-ItemAlias.html Of course the (949-) is example, I want to remove the number and dash when i redirect the URLs. What is the changes i have to do in .htaccess?

1

There are 1 answers

0
Shaun Noonan On

Your regex should match the number, but not include it in the ()'s. ex:

RewriteRule ^newsroom/press-release/item/[0-9]*-(.*)$ /press/$1 [R=301,NC,L]

The [0-9]* matches an arbitrary length number, followed by the -. Only what's matched parens will be included in $1.