在 URL 和 .htaccess 中使用空格 [英] Using spaces in URL and .htaccess

查看:22
本文介绍了在 URL 和 .htaccess 中使用空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我所在的城市编写了一个本地名称/电话/地址搜索引擎.

I wrote a local name/phone/address search engine for my city.

用户必须能够通过访问以下任一网址快速访问结果:

Users must be able to quick-access the results by going to either of these urls:

  1. 按号码搜索

这是我当前的 .htaccess 配置:

This is my current .htaccess config:

# Smart links
RewriteRule ^([0-9]+)$ /html/index.php?phone=$1 [QSA,L]
RewriteRule ^([A-Za-z-]+)$ /html/index.php?lastname=$1 [QSA,L]
RewriteRule ^([A-Za-z-]+)/([A-Za-z-]+)$ /html/index.php?lastname=$1&name=$2 [QSA,L]

效果很好,除非用户在姓氏和/或名字中包含空格.此外,搜索名称时不能使用数字.

That works pretty well, except if the user includes a space in the lastname and/or first name. Also, no numbers can be used when searching for names.

关于如何在 url 中允许空格的任何想法?谢谢!

Any ideas on how to allow spaces in the url? Thanks!

推荐答案

你能试试这个吗?([a-z-s]+)

RewriteRule ^([0-9]+)$ /html/index.php?phone=$1 [QSA,L]
RewriteRule ^([A-Za-z-s]+)$ /html/index.php?lastname=$1 [QSA,L]
RewriteRule ^([A-Za-z-s]+)/([A-Za-z-s]+)$ /html/index.php?lastname=$1&name=$2 [QSA,L]

这篇关于在 URL 和 .htaccess 中使用空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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