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

查看:171
本文介绍了在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. 按号码搜索
  1. search by number
    • http://domain.com/5554651
  • http://domain.com/smith
  • http://domain.com/smith%20johnson
  • http://domain.com/smith/andrew
  • http://domain.com/smith%20johnson/mary%20elizabeth

这是我目前的.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]

该工程pretty的很好,但如果用户包括姓氏和/或名字空间。此外,没有号码可搜索的名字时使用。

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天全站免登陆