Hi everyone Using modrewrite/htaccess my website gives the following url for images placed within a directory (example url of a image Snow - 01.jpg with spaces within file name): domain.com/pictures/Sample+Album+1/Snow+-+03.jpg.html Code (markup): How can I change that to: domain.com/pictures/Sample-Album-1/Snow-03.jpg.html Code (markup): (and if possible maybe even strip out the .jpg portion from the url so it looks like) domain.com/pictures/Sample-Album-1/Snow-03.html Code (markup): My .htacess file: AddHandler application/x-httpd-php .html Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond $1 !^(index\.php|images|css|javascript|rte|robots\.txt|jpg|cache|pictures) RewriteRule ^(.*)/(.*).html$ preview.php?catname=$1&id=$2 [QSA,L] RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond $1 !^(index\.php|images|css|javascript|rte|robots\.txt|jpg|cache|pictures) RewriteRule ^(.*) browse.php?catname=$1 [QSA,L] Code (markup): Any help is appreciated
This is a tricky one. The trouble with mapping spaces to dashes as you have done in the album name is that you can't distinguish between a file with spaces in it and a file with dashes in it. If the original name was "Sample-Album-1" the URL would end up the same as if the original name were "Sample Album 1" or even "Sample-Album 1". You could solve this by making sure that you never had any dashes in your file names but if you can do that then you could just make sure you never have spaces in your file names. If you get rid of spaces as you have done with the image name then you will have trouble finding out what the original image name was. You will also be unable to tell the difference between an original image name with spaces and one without spaces. For instance, this URL "Snow-03.jpg.html" could refer to this original image: "Snow-03.jpg" or this one: "Snow - 03.jpg" or even this one: "Snow - 03.jpg". If you drop the ".jpg" from the URL then you can't tell the difference between "Snow-03.jpg" and "Snow-03.gif" and "Snow-03.png" or even "Snow-03.JPG" (Although if you are on Windows this last one won't matter.) What we need to achieve is a one-to-one mapping from URLs to filenames. If you can make sure that your album names never have any dashes in them then that part will work fine. If you can make sure that you only ever upload jpg files or that you only ever upload one image with the same name and different extensions (i.e Don't upload "Snow-03.jpg" and "Snow-03.png" but either one is fine.) then we can drop the .jpg extension from the URL. I just can't see any way of dropping the spaces from the image name without replacing them with something else and if you do replace them with something else then you can't use that something else in any of the filenames.
That shouldn't be a problem for the files I have since I don't use any dashes in the filenames. Just wondering whether you know the code to make this possible. Thanks
You could use some PHP URL 'factory' code to remove any unwanted characters from your URL's (which may be extracting components from a database?) as described in the following book (I'm just working my way through it at the moment and it appears to answer your question): http://www.amazon.co.uk/Professiona...=sr_1_1?ie=UTF8&s=books&qid=1224495512&sr=8-1