views:

64

answers:

3

I'm trying to create tiny urls like this:

site.com/abc123

goes to:

site.com/index.php?token=abc123

but I keep getting redirect loops no matter what I try, or it tries to redirect to index.php?token=index.php..

Current .htaccess is:

Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?token=$1 [L]
A: 

I have answered a similar question yesterday: http://stackoverflow.com/questions/2611506/htaccess-redirect-a-dynamic-url-show-only-static-url-double-content/2611572#2611572

This should do it:

RewriteCond %{QUERY_STRING} ^token=([a-zA-Z0-9]+)$
RewriteRule ^/ /%1? [R=302,L]
WoLpH
A: 

That's strange since you have the [L] option attached to that rule. Could there be an external redirect caused by something else?

Anyway, you could limit the rule to requests for non-existing files (maybe directories, too).

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /index.php?token=$1 [L]

see http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond

VolkerK
+1  A: 

Here's what I've done (I'm redirecting alphanumeric codes like http://myurl.com/b32ad ):

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*) /index.php?token=$1 [L]
Jeffrey Berthiaume