0

I have an old site that is being rebuilt. Instead of using a folders structure, it is using sub-domains. The segments are different, but the redirect itself is pretty simple. I can handle it like so:

RewriteRule ^segment/blog/view$ http://blogs.site.com/segment/article [R=301,NE,NC,L]
RewriteRule ^segment/blog$ http://blogs.site.com/segment [R=301,NE,NC,L]

So if I had www.site.com/segment/blog, it will now go to blogs.site.com/segment. If I had www.site.com/segment/blog/view/catchy_name_goes_here, currently it redirects it to blogs.site.com/segment/article/catchy_name_goes_here and I NEED it to go here: blogs.site.com/segment/article/catchy-name-goes-here.

My issue comes from a decision to change the separator in the URI. The old articles were built with underscores '_' and the new articles are built with hyphens '-'.

How can I replace the underscores in the article titles with hyphens?

W3bGuy
  • 735
  • 7
  • 20
  • Did you try to take a look at the rewrite.log? – Andrew Nov 18 '13 at 23:41
  • No, ISAPI_Rewrite3 has a debugging feature. In FAQ - http://www.helicontech.com/forum/10648-FAQ.html you can find how to enable logging. In Helicon installation folder there's a rewrite.log that shows how the request has been processed. – Andrew Nov 19 '13 at 21:31
  • There must be something stopping it from logging. I tried enabling, but nothing would dump into the log. – W3bGuy Nov 21 '13 at 21:48

2 Answers2

0

Try these rules:

RewriteRule ^/segment/blog$ http://blogs.site.com/segment [R,I,L]

# replace _ by - repeatedly
RewriteRule ^(/segment/blog/view)/([^_]*)_+(.*)$ /$1/$2-$3 [I,N,U]

# all _s gone, now do a redirect
RewriteRule ^/segment/blog/view/([^_]+)$ http://blogs.site.com/segment/article/$1  [R,I,L,U]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks. This doesn't redirect or anything though at this time..The site is on IIS using the # Helicon ISAPI_Rewrite module version 3.1.0.64 I don't know if this matters or not with this rewriterule. Sometimes it effects things. – W3bGuy Nov 18 '13 at 18:45
  • Yes IIS might effect this. I had tested this on Apache it worked there. – anubhava Nov 18 '13 at 18:46
  • Right. The Helicon ASAPI Rewrite module allows for using htaccess rewrites on IIS. This is an old server. Any ideas or tweaks that you can think of? – W3bGuy Nov 18 '13 at 18:47
  • I retested on Apache it became: `http://blogs.site.com/segment/article/catchy-name-goes-here` which is your expected URL – anubhava Nov 18 '13 at 18:50
  • I understand that. It is not working in the environment I have to work under in this instance though. – W3bGuy Nov 18 '13 at 20:44
  • I did some reading and it seems `ASAPI` isn't very different, let me edit my answer accordingly. – anubhava Nov 18 '13 at 21:06
0

I ended up having to use the following. I don't know how many people this might effect due to the unique settings for this site in particular, but thought I would post the answer so it could help anyone that might need it.

The full settings on this are a server running IIS with Server 2k. The site consists of several static content pages, vb script, classic ASP, dot Net, and this is all intertwined with ExpressionEngine pages. It's a mess to say the least. To top it off, Helicon Tech's ASAPI Rewrite Module version 3 is running on the server for .htaccess usage. No sub-expressions, groupings, etc. were taking or being followed/processed. The index.php rule was getting bypassed as well.

This all said, I ended up with the following which parsed everything I needed.

RewriteRule ^index.php/segment/blog/view/([^_]*)_+(.*)$ http://www.site.com/index.php/segment/blog/view/$1-$2 [R,NC]
RewriteRule ^index.php/segment/blog/view/([^_]*)$ http://blogs.site.com/segment/article/$1  [R=301,I,L,U]
RewriteRule ^segment/blog$ http://blogs.site.com/segment [R=301,NE,NC,L]
RewriteRule ^/segment/blog$ http://blogs.site.com/segment [R,I,L]
W3bGuy
  • 735
  • 7
  • 20