Forum Moderators: phranque
# Skip the next four rules if the originally-requested URL contains no spaces
RewriteRule !^[^\ ]*\ .*$ - [S=4]
#
# SPACE-TO-HYPHEN-CONVERSION REDIRECT RULESET
#
# For "special-format" URL-paths, drop all but the "S" URL-path-part, append ".htm", put
# the result into the myURLpath variable unless already done, and skip the next rule
RewriteCond %{ENV:myURLpath} =""
RewriteRule ^[0-9]+-PG[0-9]*-[0-9]*-V[^/]*/P[~A-Za-z0-9]*-S([^/]*)/ - [E=myURLpath:$1.htm,S=1]
#
# Else copy the requested URL-path as-is to the myURLpath variable unless already done
RewriteCond %{ENV:myURLpath} =""
RewriteRule ^(.*)$ - [E=myURLpath:$1]
#
# Replace one space in the copied URL-path with a hyphen, then re-start mod_rewrite processing
RewriteCond %{ENV:myURLpath} ^([^\ ]*)\ (.*)$
RewriteRule ^ - [E=myURLpath:%1-%2,N]
#
# If no spaces remain in the copied URL-path, externally redirect to the new hyphenated URL
RewriteRule ^ http://%{HTTP_HOST}/%{ENV:myURLpath} [R=301,L]
#
# END SPACE-TO-HYPHEN-CONVERSION REDIRECT RULESET
#
# Redirect "special-format" URL-path requests that did not contain spaces in the "S" path-part
RewriteRule ^[0-9]+-PG[0-9]*-[0-9]*-V[^/]*/P[~A-Za-z0-9]*-S([^/]*)/ http://%{HTTP_HOST}/$1.htm [R=301,L]
[edited by: jdMorgan at 5:09 pm (utc) on Jan 9, 2011]