如何在 .htaccess 文件中使用空格和非 ascii 字符

发布于 2024-09-24 14:50:36 字数 213 浏览 0 评论 0原文

在 .htaccess imposibla 中使用空格、非拉丁字符等? 例如,如何解决这个问题:

RewriteRule ^/(.*)/new user/(.*)$ /page/?id=$1 [QSA,L,E]

这个决定不是我做的:

... /new_user/ ...

谢谢

in .htaccess imposibla use space, non-Latin characters and etc. ?
For example how, fix this:

RewriteRule ^/(.*)/new user/(.*)$ /page/?id=$1 [QSA,L,E]

this decision is not me:

... /new_user/ ...

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浪推晚风 2024-10-01 14:50:36

您必须使用百分号编码中各自的字符代码对 URI 的保留字符进行转义,例如 %20 表示空格。

有关更多信息,请参阅 http://en.wikipedia.org/wiki/Percent-encoding细节。

You have to escape the reserved characters for URIs with their respective character codes in percent-encoding, e. g. %20 for a space.

See http://en.wikipedia.org/wiki/Percent-encoding for more details.

不可一世的女人 2024-10-01 14:50:36

好的..网址中允许使用符号:
http://www.blooberry.com/indexdot/html/topics/urlencoding。嗯
并在 htaccess 中:

RewriteRule ^(([0-9]+)-)?new_user(-([0-9]+))?/?$   new_user.php?page=$2&id=$4 [L] 

更改 www.blabla.com/10-new_user-5
www.blabla.com/new_user.php?page=10&id=5

OK .. signs allowed in url:
http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
and in htaccess:

RewriteRule ^(([0-9]+)-)?new_user(-([0-9]+))?/?$   new_user.php?page=$2&id=$4 [L] 

change www.blabla.com/10-new_user-5
to www.blabla.com/new_user.php?page=10&id=5

情徒 2024-10-01 14:50:36

URL 在您的规则对其进行操作之前会自动解码,因此您可以针对文字字符进行测试,例如 français\ español (请注意,您需要使用反斜杠转义文字空格,除非模式被引用) 。

然而,根据你的例子,我认为你真正关心的是能够做这样的事情:

RewriteRule ^([^/]+)/[^/]+/.*$ /page/?id=$1 [QSA,L]
#                    ^---^
#                       it doesn't matter what the user name is, as long as it
#                       doesn't contain a slash

The URL is automatically decoded before your rules operate on it, so you can test against literal characters, e.g. français\ español (note that you need to escape literal spaces with a backslash, unless the pattern is quoted).

However, based on your example, I think your actual concern is being able to do something like this:

RewriteRule ^([^/]+)/[^/]+/.*$ /page/?id=$1 [QSA,L]
#                    ^---^
#                       it doesn't matter what the user name is, as long as it
#                       doesn't contain a slash
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文