How to Replace part of URL via htaccess Rewrite Rule?

Find best Web Development tips and Tricks.
Post Reply
arnlweb
Site Admin
Posts: 92
Joined: Wed Jun 22, 2016 1:28 pm
Location: India
Contact:

How to Replace part of URL via htaccess Rewrite Rule?

Post by arnlweb » Tue Oct 10, 2017 9:44 am

Replaceing word mp3 to xuna.

htaccess search and replace.

http://example.com/mp3/the-beatles-come-together

http://example.com/xuna/the-beatles-come-together

Code: Select all

# Arnlweb
# Replace 'mp3' with 'xuna' and 301 redirect 
RewriteRule ^(.*)/mp3/(.*)$ $1/xuna/$2 [R=301,L]
RewriteRule ^mp3/(.*)$ xuna/$1 [R=301,L]
# Arnlweb

Post Reply