开发者

Trying to create tiny urls, getting redirect loop

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=开发者_如何学Pythonindex.php..

Current .htaccess is:

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


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]


I have answered a similar question yesterday: htaccess: Redirect a Dynamic URL - Show only Static URL - Double Content

This should do it:

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜