srikanth saladi
srikanth saladi

Reputation: 27

301 redirect for url containing underscores

I want to

redirect /directsystems/education/index/name/system_one

TO

http://www.mysite.com/directsystems/education/index/name/system-one

Can you please show me the 301 redirect rule for htaccess? As i want to redirect undescores with hypens

Upvotes: 0

Views: 647

Answers (2)

anubhava
anubhava

Reputation: 785276

To replace all underscores _ with hyphen - in URI, use following rules in your .htaccess file:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteRule ^([^\_]+)_([^\_]+)(_.*)$ /$1-$2$3 [N,DPI]
RewriteRule ^([^\_]+)_(.*)$ /$1-$2 [L,R=301,DPI]

This redirects a URL of:

http://localhost/directsystems/education/index/my_name/system_one

to

http://localhost//directsystems/education/index/my-name/system-one

Upvotes: 1

Rajeev
Rajeev

Reputation: 4839

Try this:

RewriteRule ^([^_]*)_([^_]*)$ $1-$2

Upvotes: 0

Related Questions