Forum Moderators: phranque
Here's a brute-force (but "safe") solution that handles %20 occurring within the requested filepath, but not at the beginning or the end. This will handle up to three spaces (%20). If you need more, just add more rules, following the established template. If you don't need to handle three instances, delete the longer lines at the beginning, and leave the shorter ones.
By the time this .htaccess code is processed, the server has translated all %-encoded characters to their ASCII character equivalents. Since %20 is a space, this code simply looks for spaces and converts them to hyphens.
# Rewrite up to three instances of "%20" to "-" in URL and do a 301-Moved Permanently redirect.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ([^\ ]+)\ ([^\ ]+)\ ([^\ ]+)\ (.+) http://www.yourdomain.com/$1-$2-$3-$4 [R=301,L]
RewriteRule ([^\ ]+)\ ([^\ ]+)\ (.+) http://www.yourdomain.com/$1-$2-$3 [R=301,L]
RewriteRule ([^\ ]+)\ (.+) http://www.yourdomain.com/$1-$2 [R=301,L]
Thanks a lot for the code help.
I am a bit confused.
I was able to throw togehter the following:
RewriteRule threads/(.*)[[:space:]](.*)$ spaceredirectthreads/$1_$2 [L]
# If the URI contains ``spaceredirect''
# it means that I will have to make an external redirection
RewriteCond %{REQUEST_URI} ^/KCS/spaceredirectthreads/(.+)$ [NC]
RewriteRule . /KCS/threads/%1 [R,L]
RewriteRule ^threads(/([^/]+))?/?$ threads.php?type=$2 [L]
RewriteRule ^threads/([^/]+)/([^/]+)/?$ threads.phptype=$1&groupName=$2
This is working for things like: KCS/threads/Man_On_the_moon
It is NOT working for something like: KCS/threads/Man_on_the_moon/Hello_there
Instead it returns:
KCS/threads/Man%20on%20the%20moon/Hello%20there
Any clue how I go about getting to work for the second example?
I'm new to this mod_rewrite stuff... it's all so confusing!
Thanks!
Aaron