需要一个mod_rewrite的的.htaccess解决方案,以取代20%的空间与-'s在成品网址成品、解决方案、网址、空间

2023-09-02 00:59:08 作者:生气要吃糖

我需要一个.htaccess mod_rewrite的解决方案,将采取这样的cgi的搜索查询:

I need an .htaccess mod_rewrite solution that will take a .cgi search query like this:

www.mydomain.com/cgi-bin/finda/therapist.cgi?Therapy_Type=Pilates培训与市=洛杉矶和放大器;国= CA

www.mydomain.com/cgi-bin/finda/therapist.cgi?Therapy_Type=Pilates Training&City=Los Angeles&State=CA

和返回匹配结果在浏览器的地址栏是这样的:

and return matching results in the browser's address bar to look like this:

www.mydomain.com/therapists/Pilates-Training-Los-Angeles-CA.html

或者更好的:

www.mydomain.com/therapists/pilates-training-los-angeles-ca.html

注意,数据库包括一个,两个或三个词+空格值...

Notice the database includes values with one, two or three words + spaces...

例如:

Therapy_Type=Pilates Training <- includes a space

City=Los Angeles <- includes a space

State=CA <- no space

http://www.generateit.net/mod-rewrite/ 生成以下重写规则:

I used the tool at: http://www.generateit.net/mod-rewrite/ to generate the following RewriteRule:

RewriteEngine On
RewriteRule ^([^-]*)-([^-]*)-([^-]*).html$ /cgi-bin/finda/therapist.cgi?Therapy_Types=$1&City=$2&State=$3 [L]

这确实工作(搜索到搜索匹配),并生成结果页面,但由于参数值在他们的空间,我们最终得到的是这样的一个网址:

This does work (finds the search matches) and generates the results page, but because the parameter values have spaces in them, we end up with a URL that looks like this:

www.mydomain.com/therapists/Pilates%20Training-Los%20Angeles-CA.html

www.mydomain.com/therapists/Pilates%20Training-Los%20Angeles-CA.html

我已经花了好几天在这个论坛和其他人试图找到一个解决办法来摆脱这些20%(EN codeD空格)的因此最终返回的URL看起来像1)或2)以上。

I've spent days in this forum and others trying to find a solution to get rid of these %20 (encoded spaces) so the final returned URL will look like 1) or 2) above.

我知道有人在这里必须知道如何做到这一点...帮助; - )

I know someone on here must know how to do this... Help ;-)

推荐答案

如果你更换了20% - ,那么你将如何知道哪里有治疗类型结束,我市启动

If you replace the %20 with -, then how would you know where the therapy type ends and the city starts?

pilates-training-los-angeles-ca

type=pilates
city=training
state=los

所以,我不认为你想通过更换%,20 - 。你可以用另一个字符替换但是,像_:

So I don't think you like to replace the %20 by -. You could however replace it with another character, like _:

pilates_training-los_angeles-ca

您那么将有你的PHP脚本(或任何你正在使用的服务器端语言)中的每个_翻译到空间。

You then would have to translate every _ to a space within your PHP script (or whatever language you are using server side).