1

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

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]
4

3 回答 3

1

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]
于 2010-04-12T03:12:57.553 回答
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]
于 2010-04-12T03:09:30.967 回答
0

这很奇怪,因为您可以[L]选择附加到该规则。会不会有其他原因引起的外部重定向?

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

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

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

于 2010-04-12T03:10:30.310 回答