301 重定向附加 ?_url
301 Redirection is appending ?_url
我正在尝试为使用 Phalcon Framework 构建的网站设置 301 重定向。
问题
我的重定向工作正常,但它在重定向后附加了一个 ?_url=
和旧的 url。
默认.htaccess
以下是 .htaccess
中 Phalcon 框架附带的内容:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/ [QSA,L]
例子
当用户继续 http://example.net/fr/le-circuit/a-propos
时,它正在重定向到 http://example.net/fr/circuit?_url=/fr/le-circuit/a-propos
如您所见,?_url=
是我要删除的额外内容。
我的.htaccess
这是我的 .htaccess
没有重定向:
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirection for old website links
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [L,R=301]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/ [QSA,L]
</IfModule>
尝试 #1
我尝试了以下重定向指令 before
和 after
Phalcon 附带的默认重写规则。
Redirect 301 /fr/le-circuit/a-propos /fr/circuit
尝试 #2
我认为我的第一次尝试不够严格,所以我决定使用正则表达式和 RedirectMatch:
RedirectMatch 301 ^/fr/le-circuit/a-propos/?$ /fr/circuit
就像以前一样,我在 Phalcon 附带的规则之前和之后都试过了,它在重定向之后附加了旧的 url。
尝试 #3
我尝试在重定向中对 url 进行硬编码,以查看 ?_url=
是否仍会附加并且......是的。
RewriteMatch 301 ^/fr/le-circuit/a-propos/?$ http://example.net/fr/circuit
有谁知道这个问题或知道为什么它在重定向后附加旧的 url?
将重定向规则放在其他规则之前:
RewriteEngine On
# Redirection for old website links
RewriteRule ^fr/le-circuit/a-propos/?$ http://example.net/fr/circuit [L,NC,R=301]
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [L,R=301]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/ [QSA,L]
确保在测试此更改时清除浏览器缓存。
确保在使用 301 永久重定向时清除缓存。始终将它们调试为 302 临时重定向。当您注释掉 .htaccess 文件中的重定向时,请确保清除缓存可以防止重定向发生。完成后,您可以尝试以下建议:
完全放弃“_url”,改用 bootstrap 中的 REQUEST_URI:
使用 RewriteRule .* index.php [L]
而不是:RewriteRule ^(.*)$ index.php?_url=/ [QSA,L]
然后在 index.php bootstrap:
中使用这一行
echo $application->handle(strtok($_SERVER["REQUEST_URI"],'?'))->getContent();
而不是 echo $application->handle()->getContent();
默认处理 $_GET['_url']
.
我正在尝试为使用 Phalcon Framework 构建的网站设置 301 重定向。
问题
我的重定向工作正常,但它在重定向后附加了一个 ?_url=
和旧的 url。
默认.htaccess
以下是 .htaccess
中 Phalcon 框架附带的内容:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/ [QSA,L]
例子
当用户继续 http://example.net/fr/le-circuit/a-propos
时,它正在重定向到 http://example.net/fr/circuit?_url=/fr/le-circuit/a-propos
如您所见,?_url=
是我要删除的额外内容。
我的.htaccess
这是我的 .htaccess
没有重定向:
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirection for old website links
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [L,R=301]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/ [QSA,L]
</IfModule>
尝试 #1
我尝试了以下重定向指令 before
和 after
Phalcon 附带的默认重写规则。
Redirect 301 /fr/le-circuit/a-propos /fr/circuit
尝试 #2
我认为我的第一次尝试不够严格,所以我决定使用正则表达式和 RedirectMatch:
RedirectMatch 301 ^/fr/le-circuit/a-propos/?$ /fr/circuit
就像以前一样,我在 Phalcon 附带的规则之前和之后都试过了,它在重定向之后附加了旧的 url。
尝试 #3
我尝试在重定向中对 url 进行硬编码,以查看 ?_url=
是否仍会附加并且......是的。
RewriteMatch 301 ^/fr/le-circuit/a-propos/?$ http://example.net/fr/circuit
有谁知道这个问题或知道为什么它在重定向后附加旧的 url?
将重定向规则放在其他规则之前:
RewriteEngine On
# Redirection for old website links
RewriteRule ^fr/le-circuit/a-propos/?$ http://example.net/fr/circuit [L,NC,R=301]
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [L,R=301]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/ [QSA,L]
确保在测试此更改时清除浏览器缓存。
确保在使用 301 永久重定向时清除缓存。始终将它们调试为 302 临时重定向。当您注释掉 .htaccess 文件中的重定向时,请确保清除缓存可以防止重定向发生。完成后,您可以尝试以下建议:
完全放弃“_url”,改用 bootstrap 中的 REQUEST_URI:
使用 RewriteRule .* index.php [L]
而不是:RewriteRule ^(.*)$ index.php?_url=/ [QSA,L]
然后在 index.php bootstrap:
echo $application->handle(strtok($_SERVER["REQUEST_URI"],'?'))->getContent();
而不是 echo $application->handle()->getContent();
默认处理 $_GET['_url']
.