Results 1 to 3 of 3

Thread: Strange .htaccess Problem

  1. #1

    Strange .htaccess Problem

    I am working on a project that uses a URL shortener routine. I need to translate a URL that looks like a typical short URL to one that I can process. There is a base 36 hash code that gets translated into a reference number for a database lookup.

    A typical shortened URL looks like this (spaces added so that it does not go live):

    http :// domain. com/2afc3

    I need to rewrite it into the following for processing:

    http :// domain. com?hashURL=2afc3

    It looks like it should be simple enough to rewrite the URL; however, it is not working. I am using $_SERVER['QUERY_STRING'] to monitor the querystring being passed to the script.

    I tried this.

    RewriteRule ^(.*)$ index.php?hashURL=$1 [L]

    It returns a querystring with "hashURL=index.php". I do not know where it is picking up index.php in the querystring.


    I tried this:

    RewriteRule ^index.php/(.*)$ index.php?hashURL=$1 [L]

    This generates a 404.


    I tried adding a leading slash in the rewrite rule:

    RewriteRule ^/(.*)$ index.php?hashURL=$1 [L]

    This also generates a 404.


    If I add a subdirectory, such as http: // domain. com/a/2afc3 into the URL (which I do not want to do) and use the following rewrite code:

    RewriteRule ^a/(.*)$ index.php?hashURL=$1 [L]

    It work perfectly and returns a querystring with "hashURL=2afc3".

    What am I missing? This looks like it should be simple, but I cannot seem to get the rewrite rule to read the 2afc3 hash code tacked onto the URL. I need to read the code without a reference character for a starting point. Is there any way to do that?
    Last edited by TopDogger; 18 October, 2009 at 21:46 PM.
    "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." -- Benjamin Franklin

  2. #2
    Join Date
    Oct 2009
    Bosnia and Herzegovina
    Try this:
    RewriteRule ^[a-zA-Z0-9]*$ index.php?hashURL=$0 [L]

  3. #3
    That works. Thanks.

    I actually did try that previously, but I was using $1 for the variable and had the conditional wrapped in parentheses. For some reason that did not work.
    "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." -- Benjamin Franklin

Similar Threads

  1. Something strange with my adsense
    By SonnyCooL in forum AdSense
    Replies: 5
    Last Post: 26 October, 2010, 04:48 AM
  2. .htaccess Problem
    By in forum Managing
    Replies: 1
    Last Post: 12 April, 2010, 20:11 PM
  3. went from 3 to 81 in 1 day little strange?
    By in forum Promoting
    Replies: 9
    Last Post: 15 September, 2009, 17:49 PM
  4. Strange Wii Game
    By m42 in forum Entertainment
    Replies: 2
    Last Post: 22 May, 2009, 07:43 AM
  5. Strange Google Ads?
    By Aquarezz in forum AdSense
    Replies: 2
    Last Post: 31 January, 2009, 12:17 PM

Tags for this Thread


Posting Permissions

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