Symbolic link or URL redirection?

I am not exactly a newbie here, but have no idea how to solve an apparently easy problem… so am hoping someone can help!

The idea is that I have a Webpage where the filename is
[ something_or_other.html ], with underscores between words.

How do I get
[ someting-or-other.html ], with dashes between words, to automatically redirect visitors to [ something_or_other.html ] ?

If it was just a single page, then an HTML document with a <meta http-equiv=“REFRESH” … > tag would be OK of course.

But I am talking here of a largish Website, with several hundred pages and some inconsistency in file naming, so I would need a bit too many variants of the same page for this solution to be “really OK”.

Any suggestions?

Many thanks!

are you doing a website with several hundred pages in .html files?

If so, you may want to consider switching to .php files instead. This will allow some additional options to happen that can really lighten your work and you can add some statements to check the file-name and then go to a different page if the filename has dashes.

Use mod_rewrite to redirect requests for filenames with hyphens and the .html extension to a script. The script then switches the hyphens to underscore and issues a redirect. If the number of hyphens is small you can probably just do it all with mod_rewrite alone by adding to the regexp and substitution strings.

No need for a script; this rule will do the job on its own:

Note that, while this will work if you have file names with multiple dashes, it’ll take a few cycles of redirection to get where it needs to go. Adding some additional rules will help things a bit, e.g.

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

The pattern should be pretty clear.

Thanks Andrew (and Sierracircle and Atropos) - I am not a programmer though and have no clue with either php, or the way Apache works. I apologise for that.

Would the RewriteRule above need to be included in an .htaccess file? Or is it something that would only work with php/dynamically generated pages? That is not my case - those few hundred pages are all static HTML…

Would appreciate your help with this.

Yep. Put it at the top of a .htaccess file.

Great, many thanks to all!