【发布时间】:2011-05-26 21:24:45
【问题描述】:
我正在尝试美化一些网址。我配置了 htaccess 文件,所以我的 url 被改变了:
旧网址:http://mysite.com/index.php?id=45tye4 新网址:http://mysite.com/45tye4
我现在想将旧网址永久重定向到新网址。这是我没有运气的尝试:
RewriteRule ^index.php?id=(.*)$ $1 [R=301,L]
主要问题似乎是“?”在网址中。当我尝试相同的 url 时没有 ?重定向有效。我还尝试了其他变体但没有运气:
RewriteRule ^index.php\?id=(.*)$ $1 [R=301,L]
RewriteRule ^index.php[\?]id=(.*)$ $1 [R=301,L]
更新:
我根据 anubhava 指令添加了重定向。重定向有效,但不幸的是我进入了重定向循环。我认为 [L] 标志应该解决重定向循环,但它没有。
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^index\.php/?$ /%1? [R=301,L]
RewriteRule ^(.*)$ index.php?id=$1 [L]
【问题讨论】:
标签: apache .htaccess mod-rewrite redirect url-rewriting