Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 301重定向正在附加?\u url_Php_Regex_Apache_.htaccess_Phalcon - Fatal编程技术网

Php 301重定向正在附加?\u url

Php 301重定向正在附加?\u url,php,regex,apache,.htaccess,phalcon,Php,Regex,Apache,.htaccess,Phalcon,我正在尝试设置301重定向为一个网站,建立与 问题 我的重定向工作正常,但它在重定向后用旧url追加了一个?\u url= 默认.htaccess 以下是.htaccess中的Phalcon框架附带的内容: RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L] 例子 当用户正在进行http://example.ne

我正在尝试设置301重定向为一个网站,建立与

问题 我的重定向工作正常,但它在重定向后用旧url追加了一个
?\u url=

默认.htaccess 以下是
.htaccess
中的Phalcon框架附带的内容:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
例子 当用户正在进行
http://example.net/fr/le-circuit/a-propos
,它正在重定向到
http://example.net/fr/circuit?_url=/fr/le-电路/a-propos

如您所见,
?\u 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=/$1 [QSA,L]
</IfModule>
尝试#2 我认为我的第一次尝试不够严格,所以我决定使用正则表达式和重定向匹配:

RedirectMatch 301 ^/fr/le-circuit/a-propos/?$ /fr/circuit
就像以前一样,我在Phalcon附带的规则之前和之后都试过了,它在重定向后附加了旧的url

尝试#3 我已尝试在重定向中硬编码url,以查看
?\u 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=/$1 [QSA,L]

测试此更改时,请确保清除浏览器缓存。

使用301永久重定向时,请确保清除缓存。始终将它们作为302临时重定向进行调试。确保在注释掉.htaccess文件中的重定向时,缓存清除可防止重定向发生。完成后,您可以尝试以下建议:

通过使用引导程序中的请求URI,完全放弃“\u url”:
使用
RewriteRule.*index.php[L]
代替:
RewriteRule^(.*)$index.php?\u url=/$1[QSA,L]
然后在index.php引导程序中使用此行:

echo $application->handle(strtok($_SERVER["REQUEST_URI"],'?'))->getContent();

而不是
echo$application->handle()->getContent()
默认处理
$\u GET[''u url']

谢谢!我尝试使用
重写规则
,但我的问题是我在开头添加了一个斜杠
/fr/le circuit/a-propo/?$
,如果没有斜杠,规则就像魅力一样!
echo $application->handle(strtok($_SERVER["REQUEST_URI"],'?'))->getContent();