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

发布于 2024-08-28 20:54:04 字数 381 浏览 6 评论 0原文

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

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]

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

彻夜缠绵 2024-09-04 20:54:04

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

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
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]
海未深 2024-09-04 20:54:04

我昨天回答了类似的问题: htaccess:重定向动态 URL - 仅显示静态 URL - 双内容

这应该可以做到:

RewriteCond %{QUERY_STRING} ^token=([a-zA-Z0-9]+)$
RewriteRule ^/ /%1? [R=302,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]
可爱暴击 2024-09-04 20:54:04

这很奇怪,因为您已将 [L] 选项附加到该规则。是否可能存在由其他原因引起的外部重定向?

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

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文