I'm trying to rewrite a url from the following. The URL looks like this www.site.com/page?name=Digital+Point+Forums I want to change it to /directory/Digital-Point-Forums I'm not sure how to do this. This is what I got so far. I can't figure out if it's possible or not to substitute the + for the hyphens. RewriteRule ^/directory/(.*) page?name=$1 [L]
RewriteRule ^directory/([^-]+)-([^-]+)-([^-]+)-([^-]+)-([^-]+)$ page?name=$1+$2+$3+$4+$5 RewriteRule ^directory/([^-]+)-([^-]+)-([^-]+)-([^-]+)$ page?name=$1+$2+$3+$4 RewriteRule ^directory/([^-]+)-([^-]+)-([^-]+)$ page?name=$1+$2+$3 RewriteRule ^directory/([^-]+)-([^-]+)$ page?name=$1+$2 RewriteRule ^directory/(.*)$ page?name=$1 Code (markup): That should catch each word with the hyphen (-), and send it out with a plus (+). It, as you can see, only supports up to 5 hyphens (catching each URL in turn). It's untested, but I'm sure you can use it as a base for something brilliant. Just my theory. Jay
Thanks Jay. That code isn't working for me. I'm playing around with it to get it to work. I've been trying \w+ and other word combinations. No luck yet though. Thanks.
Ok. I got it working now. I did three things. 1. I changed ([^-]+) to (.*) . 2. I took the /directory/ part out. I found that the first match would try to grab the directory part and I couldn't control it. 3. I had a previous line in my .htaccess file that was very similar. So I changed the file extension from .html to .htm. This seems to work for me. Thanks.