用UTF-8字符的.htaccess重定向的URL [英] .htaccess Redirect URLs with UTF 8 chars

查看:112
本文介绍了用UTF-8字符的.htaccess重定向的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想所有非subdomained请求重定向到www,而preserving请求URI。

I am trying to redirect all non-subdomained requests to www while preserving the request URI.

我在我的重定向.htaccess文件使用这样的:

I am using this in my .htaccess file for the redirect:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=302]

问题是,虽然当我有这样的要求:

The problem though is that when I have a request like this:

example.com/search/?name=läkare

example.com/search/?name=läkare

重定向到:

www.example.com/search/?name=l%25C3%25A4kare

这是一种不正确,被编码两次。我检查一下这个:

Which is kind of incorrect, it is encoding it twice. I check it with this:

<?php

echo rawurlencode('läkare');//outputs l%C3%A4kare
echo "\n";
echo rawurldecode('l%25C3%25A4kare');//outputs l%C3%A4kare
echo "\n";
echo rawurldecode(rawurldecode('l%25C3%25A4kare'));//outputs läkare

为什么编码了两遍,我怎么不让它这样做?我行与1编码,但2实在是太多了。

Why is it encoding it twice and how do I keep it from doing that? I am ok with 1 encoding but 2 is too much.

推荐答案

您需要的 NE (无路可逃)改写标志为您的规则。将prevent已经逃出查询字符串从获得双重转义:

You need the NE (no escape) rewrite flag for your rule. That will prevent the already escaped query string from getting double escaped:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=302,NE]

这篇关于用UTF-8字符的.htaccess重定向的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆