特殊字符和放大器; URL重写放大器、重写、特殊字符、URL

2023-09-02 00:49:56 作者:国王与乞丐。

我目前正在从暴雪社区API拉JSON数据,并用PHP解析它的应用程序。一切工作好,直到我来,在他们的名字一个特殊字符的字符。

为了拉动字符数据,我需要知道自己的角色名和领域,他们都在。

我的名字和领域正在通过的URL字符页面,并从那里使用该信息来拉动字符数据。

在这一点上我的网址是像这样:

 的http://localhost/guildtree/characters.php境界=银色黎明和放大器;名称= Ankzu
 

在这一点上,如果我尝试把数据与口音我得到重定向到我的错误页面字符,因为它不是一个有效的字符。

直到我开始重写,我发现我的问题的URL。我被重定向到我的错误页面,因为沿特殊字符被替换一些非常靠不住的字符行的地方。

不只是特殊字符怎么打那么简单 Win7自制特殊符号方法

使用我的新的URL重写后续工作:

 的http://本地主机/ guildtree /银色黎明/ ankzu
 

然而,在他们的名字结果的特殊字符错误消息的字符。

 的http://本地主机/ guildtree /银色黎明/notúk
 

将导致以下错误信息:

未找到

所请求的网址/ guildtree /银色黎明/notúk在此服务器上找到。

正如你可以看到U是被取代ú,但是当我复制和粘贴网址的U显示为%C3%BA

这是我的理解是,为什么U是表现为ú的原因是因为两个字节的UNI code u是被压扁成导致ú显示两个一字节的ASCII字符。

我已经确保了我所有的网页都在标题中的下列内容:

 < META HTTP-当量=Content-Type的CONTENT =text / html的;字符集= UTF-8/>
 

为了我的应用程序正常工作,我需要这些特殊字符,显示正常,所以我需要在U实际显示为U,不会出现如u,但实际上是ú或%C3%BA。

字符名称被从URL拉出简单地为:

  $ CHARNAME = $ _GET ['名称'];
 

是否可以连接code $ CHARNAME正确显示特殊字符?

我已经试过各种我能想到的,搜索在谷歌,但没有奏效。

此外,由于我使用的URL重写什么重写规则是允许这些特殊字符?

下面是我目前的重写规则:

 重写规则^([A-ZA-Z0-9 _'-] +)/([A-ZA-Z] +)$ characters.php境界= $ 1安培;名= $ 2 [NC]
 

我知道,([A-ZA-Z] +)不允许在所有的特殊字符,我现在一直在努力得到特殊字符正确显示。如果使用([A-ZA-Z ú] +),将工作并显示该网页,因为它需要被显示。添加ú的规则似乎是一个非常穷的方式来做到这一点,在使用相应的字符重音字符并不总是工作。

任何帮助将是很大的AP preciated。如果您需要了解更多信息请咨询。

编辑:

更改我重写规则下面允许信息被拉细,但对我的CSS创建一个重定向循环。

 重写规则^([A-ZA-Z0-9 _'-] +)/([^ /] +)1 $ characters.php境界= $&放大器;名称= $ 2 [ NC]
 

例如我的CSS被重定向到

 的http://本地主机/ guildtree / CSS /错误
 

而不是

  HTTP://localhost/guildtree/css/style2.css
 

更新:

通过几个简单的测试:

  $ CHARNAME = $ _GET ['名称'];
$ charNameTEST = utf8_en code($ CHARNAME);
 

将做出改变,但是当我将此运用到我的网页仍然出现说:

未找到

所请求的网址/ guildtree /银色黎明/notúk在此服务器上找到。

我觉得主要的问题,现在是用URL重定向,因为JSON数据可以分析完全正常时,它有重音符号。我只是不明白为什么它一直显示我,这是对guildtree /银色黎明/notúk在浏览器栏,而是不停地尝试拉/ guildtree /银色黎明/notúk。

解决方案

U是不是一个有效的字符,对于一个URL。

无论你链接的用户名,您应该URL-CN code吧。

因此​​,要指向正确的网址是:

 的http://本地主机/ guildtree /银色黎明/未%C3%比克
 

您应该在PHP中打印为:

 回声< A HREF =HTTP://本地主机/ guildtree /银色黎明/'。urlen code($名称)'>链接< / a取代;;
 

I am currently working on an application that pulls JSON data from the blizzard community API and parses it with PHP. Everything works okay until I come to a character with a special character in their name.

In order to pull the characters data I need to know their characters name and realm that they are on.

I have the name and realm being passed through the URL to the character page, and from there using that information to pull the character data.

At this point my URLs are like so:

 http://localhost/guildtree/characters.php?realm=argent-dawn&name=Ankzu

At this point if I try to pull data for a character with an accent I get re-directed to my error page because it is not a valid character.

It wasn't until I started the URL rewriting that I discovered my problem. I am being re-directed to my error page because somewhere along the line the special characters are being substituted for some really wonky characters.

With my new rewritten URLs the follow works:

 http://localhost/guildtree/argent-dawn/ankzu

However, a character with a special character in their name results in an error message.

 http://localhost/guildtree/argent-dawn/notúk

Results in the following error message:

"Not Found

The requested URL /guildtree/argent-dawn/notúk was not found on this server."

As you can see the ú is being substituted for ú, but when I copy and paste the URL the ú appears as %C3%BA

It is my understanding that the reason why the ú is appearing as ú is because the two byte unicode ú is being squished into two one byte ASCII characters resulting in the ú being displayed.

I have ensured that all my pages have the following in the header:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

In order for my application to work properly I need those special characters to display properly, so I need the ú to actually display as ú, not appear as ú but actually be ú or %C3%BA.

The characters name is being pulled from the URL simply as:

$charName = $_GET['name'];

Is it possible to encode $charName to display the special characters properly?

I have tried everything I can think of and have searched on Google but nothing has worked.

Also, because I am using URL rewriting what would the rewrite rule be to allow for these special characters?

Here is my current rewrite rule:

 RewriteRule ^([a-zA-Z0-9_'-]+)/([a-zA-Z]+)$        characters.php?realm=$1&name=$2     [NC]

I'm aware that ([a-zA-Z]+) does not allow at all for special characters, I have currently been working on getting the special characters to display properly. If I use ([a-zA-Zú]+) it will work and display the page as it needs to be displayed. Adding the ú to the rule seems like a very poor way to do this and does not always work while using the corresponding character for the accented characters.

Any help would be greatly appreciated. If you require any more information please ask.

Edit:

Changing my rewrite rule to the below allows for the information to be pulled fine, but creates a redirect loop for my CSS.

 RewriteRule ^([a-zA-Z0-9_'-]+)/([^/]+)$        characters.php?realm=$1&name=$2 [NC]

For example my CSS is being redirected to

http://localhost/guildtree/css/error

instead of

http://localhost/guildtree/css/style2.css

Update:

Through a few simple tests:

$charName = $_GET['name'];
$charNameTEST = utf8_encode($charName);

Will make the change, but when I apply this to my page it still comes up saying:

"Not Found

The requested URL /guildtree/argent-dawn/notúk was not found on this server."

I think the main issue now is with the URL redirecting, because the JSON data can be parsed perfectly fine when it has the accented characters. I just don't understand why it keeps showing me that it is on guildtree/argent-dawn/notúk in the browser bar, but keeps trying to pull up /guildtree/argent-dawn/notúk.

解决方案

ú is not a valid character, for a URL.

Wherever you link the username, you should URL-encode it.

Hence the correct URL to point to is:

http://localhost/guildtree/argent-dawn/not%C3%BAk

You should print it in php as:

echo '<a href="http://localhost/guildtree/argent-dawn/'. urlencode($name) .'">Link</a>;