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
Bookmarks