Forum Moderators: phranque

Message Too Old, No Replies

htaccess rewrite regexp question

How to replace ALL underbars with dashes?

         

craig1972

2:02 pm on Nov 26, 2003 (gmt 0)

10+ Year Member



Hi,

I want a rule in my .htaccess file whereby I can replace all the underbars in a URL to dashes. How should I do this?

For example, let us say that user types this URL:


http://mydomain.com/one_big_url.html

Then I want to change this automatically to:

http://mydomain.com/one-big-url.html

I can find and replace one or two underbars with following scheme:

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


But the problem is that I don't know how many underbars are present in the URL. Different pages have different numbers.

Does anyone know how to "match all" the underbars and replace them with dashes?

Thanks!

jim_w

2:08 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Personally, I would not do that. I did exactly that, but not in .htaccess, when I was ranking well, pre-FL, and now I’m nowhere to be found. I’m listed in G, but I don’t come up for my KW’s.

While that may not be the reason I cannot be found for my KW’s, it is one of my 3 best guesses as to why.

But that is just my opinion.

craig1972

3:53 pm on Nov 28, 2003 (gmt 0)

10+ Year Member



Ok, to anyone looking for this stuff in the future, I just put some logic in the 404.shtml file on my server to check for underscores and "recommend" the same path with bars.

Thanks.