重写URL包含空格 [英] Rewrite URL containing spaces
问题描述
我有以下格式的网址:域/ product.php?NAME =产品A
I have an url with the following format:
domain/product.php?name=product a
现在我需要重写这:域/产品中
(包括该字的空间),如: http://www.directline-holidays.co.uk/Costa布兰卡
Now I need to rewrite this to:
domain/product a
(including the space in the word) like:
http://www.directline-holidays.co.uk/Costa Blanca
我如何做到这一点?我走到这一步,最近的结果如下:域/ P /产品-A
How do I do this? The closest result I got so far is the following:
domain/p/product-a
通过在.htaccess以下code
With the following code in .htaccess
RewriteEngine On
RewriteRule ^p/([^/]*)/$ destination.php?name=$1
我甚至不能使用名称不带 - 。我所需要的产品的名称只是因为它是在数据库中。这可能吗?
I could not even use the name without the "-". I need the product name just as it is in the database. Is this possible?
推荐答案
这应该工作:它只是给你的URL字符串的其余/ P /目录到字符串的结尾,在这之后你的情况应该是URL的末尾,是否正确?
This should work: It will simply give you the rest of the URL string after the /p/ directory to the end of the string, which in your case should be the end of the URL, correct?
RewriteRule ^p/(.*)$ destination.php?name=$1
对于不是产品页面,如果你知道他们会在PHP文件扩展名,你可以过滤以下的规则这些页面结束网页:
For the pages that are not product pages, if you know they will end in a .php file extension you can filter for those pages with the following rule:
RewriteCond %{REQUEST_URI} !^.*(destination\.php).*$
RewriteRule ^([^\.php]+)$ destination.php?name=$1
编辑:通过添加destination.php的RewriteCond修正了无限循环的情况。
Fixed for infinite loop condition by adding RewriteCond for destination.php
这篇关于重写URL包含空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!