sanitycheck
sanitycheck

Reputation: 298

change underscores to hyphens in URLs with file names that begin with the word article

I tried using some code I found elsewhere on stackoverflow, but I want to modify it, and I don't know how.

RewriteRule ^([^_]*)_+(.*)$ $1-$2 [E=underscores:Yes,N]
RewriteCond %{ENV:underscores} ^Yes$
RewriteRule ^(.+)$ /$1 [R=301,L]

This changes all underscores to hyphens. However, I need to limit this set of statements to only URLs that begin:

http://www.mydomain.tld/article...

In other words, the rules should only apply when the file name begins with the word article.

Can someone help?

Upvotes: 0

Views: 400

Answers (1)

Panama Jack
Panama Jack

Reputation: 24458

Try this and see if this and see if it works for you..

RewriteRule ^([^_]*)_+(.*)$ $1-$2 [E=underscores:Yes,N]
RewriteCond %{ENV:underscores} ^Yes$
RewriteRule ^article(.+)$ /article$1 [R=301,L]

Upvotes: 1

Related Questions