Topic: Replacing underscores with hyphens
|

|
| Author |
|
awzm Newbie

Joined: 27 July 2010
Online Status: Offline Posts: 3
|
| Posted: 27 July 2010 at 3:44am | IP Logged
|
|
|
Hi there,
I've rewritten a fair few hundred URLs in our CMS system and replaced a lot fo the existing URLs that did have underscores with hyphens. I've written a Rewriterule to do a straight port for URLs that were already hyphentated over to the new location. However I'm stuck on replacing the underscores with hyphens in ISAPI.
This forum post is as close as I could find to the correct script: http://www.helicontech.com/forum/10756-replace_underscore_with_space.html
The issue I have is I can have a page like 'folder/A_B_C.htm' or just 'folder/A_B.htm' so I need to take into account one or two underscores at a time...maybe done through seperate rules?
Any help would be greatly appreciated!
Thanks.
|
| Back to Top |
|
| |
AndrushkaUS Senior Member

Joined: 13 November 2009 Location: United States
Online Status: Offline Posts: 1545
|
| Posted: 27 July 2010 at 6:01am | IP Logged
|
|
|
Hello,
Please, try to use the following:
Code:
RewriteEngine on
RewriteBase /
RewriteRule ^(folder/[^_/]+)_([^_/])\.html$ $1-$2.html [NC,R=301,L]
RewriteRule ^(folder/[^_/]+)_([^_/])_([^_/])\.html$ $1-$2-$3.html [NC,R=301,L] |
|
|
Regards
Andrew
__________________ The will to conquer is the first condition of VICTORY
|
| Back to Top |
|
| |
awzm Newbie

Joined: 27 July 2010
Online Status: Offline Posts: 3
|
| Posted: 27 July 2010 at 8:21am | IP Logged
|
|
|
Hi Andrew,
Thanks for the prompt reply. I adapted the code slightly as I missed out a folder level, here is what I have now...
Code:
RewriteEngine On RewriteBase /
RewriteRule ^(/folder1/folder2/[^_/]+)_([^_/])\.htm$ http://www.newdomain.co.uk/folder1/folder2/$1-$2.html [NC,R=301,L] RewriteRule ^(/folder1/folder2/[^_/]+)_([^_/])_([^_/])\.htm$ http://www.newdomain.co.uk/folder1/folder2/$1-$2-$3.html [NC,R=301,L]
RewriteRule ^/folder1/(.*)/(.*).htm http://www.newdomain.co.uk/folder1/$1/$2.htm [NC,L]
|
|
|
Having tried that it doesn't seem to have worked, I'm just getting 404s. The third rule in there is simply to handle pages that were hyphenated before.
|
| Back to Top |
|
| |
awzm Newbie

Joined: 27 July 2010
Online Status: Offline Posts: 3
|
| Posted: 28 July 2010 at 9:57am | IP Logged
|
|
|
*bump*
|
| Back to Top |
|
| |
AndrushkaUS Senior Member

Joined: 13 November 2009 Location: United States
Online Status: Offline Posts: 1545
|
| Posted: 29 July 2010 at 4:14am | IP Logged
|
|
|
I think you should try to replace
Code:
| RewriteRule ^(/folder1/folder2/[^_/]+)_([^_/])\.htm$ http://www.newdomain.co.uk/folder1/folder2/$1-$2.html [NC,R=301,L] |
|
|
with
Code:
| RewriteRule ^(/folder1/folder2/[^_/]+)_([^_/])\.htm$ http://www.newdomain.co.uk/$1-$2.html [NC,R=301,L] |
|
|
and do the same for the second one.
Regards
Andrew
__________________ The will to conquer is the first condition of VICTORY
|
| Back to Top |
|
| |
|
|
If you wish to post a reply to this topic you must first login
If you are not already registered you must first register
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You can vote in polls in this forum
|