cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
New

How to redirect a bunch of pages with underscores in filenames to new paths with dashes?

I have website with 800 + pages. Many of them have underscores in filenames. I would like to replace all pages with underscores to files with dashes. For example, photoshop_tutorials.html  ----> photoshop-tutorials.html. Is any way to do it automatically? I tried to use code for .htaccess file:

RewriteEngine On
RewriteRule ^([^_]*)_([^_]*_.*) $1-$2 [N]
RewriteCond %{REQUEST_URI} !^/folder-should-not-be-redirected[/]?
RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,R=301]

This code worked, but my website was suspended because of creating some kind of loop, which takes down Godaddy servers. I removed this code, but I'm still looking the way to forward pages without creating manual redirection for each page in Godaddy redirect manager. Thank you for any advise.

1 REPLY 1
Highlighted
Retired
Not applicable

Re: How to redirect a bunch of pages with underscores in filenames to new paths with dashes?

Hi @andyfo,

there are quite a few methods that a power user can use on the command line:

 

you can can use the 'substitute' command in VIM 

http://vim.wikia.com/wiki/Search_and_replace

 

as well in SED :

https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html

 

I can't give lessons here so please RTM. 

😊