htaccess/modrewrite Question

Discussion in 'Apache' started by JazzDomains, Oct 14, 2008.

  1. #1
    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 :D
     
    JazzDomains, Oct 14, 2008 IP
  2. JazzDomains

    JazzDomains Peon

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Anybody? :)
     
    JazzDomains, Oct 16, 2008 IP
  3. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    Ladadadada, Oct 16, 2008 IP
    pondlife and JazzDomains like this.
  4. JazzDomains

    JazzDomains Peon

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4

    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 :)
     
    JazzDomains, Oct 18, 2008 IP
  5. pondlife

    pondlife Peon

    Messages:
    898
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #5
    pondlife, Oct 20, 2008 IP