Results 1 to 6 of 6
  1. #1

    htaccess rewrites

    I want to convert download.php?hash=

    to /downloads/hash

    The hash query variable is 32 characters in length and composed of both upper case and lowecase letters and numbers.

    This is what I have so far, but it isn't working.

    RewriteEngine on
    RewriteRule ^download.php?hash=(.*)$ /downloads/$1

  2. #2
    I think your doing it backwards =P

    RewriteEngine on
    RewriteRule /downloads/$1 ^download.php?hash=$1

    At least thats how I do mine...

  3. #3
    That doesn't appear to be converting this to /download/0cc......

    <a href="download.php?hash=0cc175b9c0f1b6a831c399e269772661">test</a>

  4. #4
    Have you uh tried
    <a href="download/0cc175b9c0f1b6a831c399e269772661">test</a> ?

    I dont know much about htaccess but you have to then change the URLs itself, htaccess then just makes a cover up.

  5. #5
    I just tried that and it didn't work. I used the code you provided and I've got a blank php script named, "download.php" in the directory.

  6. #6
    Join Date
    Mar 2005
    Posts
    31
    Quote Originally Posted by Adam Hallett View Post
    I just tried that and it didn't work. I used the code you provided and I've got a blank php script named, "download.php" in the directory.
    What do you mean, "it didn't work." You are going to have to be more specific than that if you want help. Did you get a blank page? 500 Internal Server Error? 404 File not Found Error? What? What did your server access and error logs say?

    Quote Originally Posted by aldo View Post
    I think your doing it backwards =P

    RewriteEngine on
    RewriteRule /downloads/$1 ^download.php?hash=$1

    At least thats how I do mine...
    Right, the first address us the "fake" one and the second is like the "real" one. But it should be:

    RewriteRule ^downloads/(.+)$ download.php?hash=$1

    or better yet since if the hash is always 32 alphanumeric characters long:

    RewriteRule ^downloads/([a-ZA-Z0-9]{32})$ download.php?hash=$1

    When you are debbuing it is helpful to put an [R] in the RewriteRule which will send a redirect to your browser (and so the url in the address bar should change) rather than silently rewriting it.

    RewriteRule ^downloads/(.+)$ download.php?hash=$1 [R]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •