views:

48

answers:

1

I've got a url - http://callisto/news/1st_February_is_here... - which has three trailing dots, but by the time it gets passed through mod_rewrite and reaches the script (in $_GET) the dots have been removed (but the rest of the string is OK).

This is the htaccess rule:

RewriteRule ^([^/]+)/(.*)$ index.php?__action=site&__filter=$1&__page=$2 [L,QSA]

Thanks.

+1  A: 

I take it you are using the title of a post or something similar as the third position in your URI. Due to the fact that you could probably have a lot of other 'breaking' characters come through your URI with this method I would suggest that you cleanse the title before appending it to the URI and place the same cleansed string into your database for reference.

Remove any characters that aren't alphanumeric and replace spaces with a hyphen '-'--this will ensure that you don't confuse anything further down the line or bump into any browser specific issues that keep your URI from working.

$title = '1st February is here...';
$clean_title = preg_replace('/[^a-zA-Z0-9\s]/', '', $title);
$finished_title = str_replace(' ', '-', $clean_title);

Running the code aboce will clean your title.

http://callisto/news/1st_February_is_here...

Should become:

http://callisto/news/1st-February-is-here

Or something similar. The only reason I suggest a hyphen instead of an underscore is that I have, on occasion, had issues with underscores being passed in the URI.

Also, I think you will find this is the method that Wordpress employs--most likely for the same reason that you are seeing this issue.

GL!

angryCodeMonkey
Not a bad idea - I do have a function that encodes and decodes the link special characters already (but no caching). I'll probably do what you suggest when I have more time as it seems a bit more bulletproof, but stick to just telling the client not to do it in the meantime :)
Meep3D
@Meep3d - Good luck getting the client to do something you ask them to do. I think that might be a first. :P
angryCodeMonkey