试图创建小网址,获得重定向循环

时间:2010-04-12 02:53:47

标签: php apache mod-rewrite tinyurl

我正在尝试创建这样的小网址:

  

site.com/abc123

转到:

  

site.com/index.php?token=abc123

但无论我尝试什么,我都会继续获取重定向循环,或者它尝试重定向到index.php?token = index.php ..

目前.htaccess是:

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

3 个答案:

答案 0 :(得分:1)

这就是我所做的(我正在重定向像http://myurl.com/b32ad这样的字母数字代码):

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

答案 1 :(得分:0)

我昨天回答了类似的问题:htaccess: Redirect a Dynamic URL - Show only Static URL - Double Content

这应该这样做:

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

答案 2 :(得分:0)

这很奇怪,因为你有[L]选项附加到该规则。是否会出现由其他内容引起的外部重定向?

无论如何,您可以将规则限制为对不存在的文件(也可能是目录)的请求。

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

请参阅http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond