htaccess url用荷兰语和英语重写

时间:2022-01-15 15:20:06

I am handle with htaccess in my subdomain.

我在子域中处理htaccess。

My htaccess script is given below

我的htaccess脚本如下

RewriteCond %{HTTP_HOST} ^demo\.example\.com/carrental$
RewriteRule (.*) carrental/([^/.]+)/([^/.]+)/([^/.]+) [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ carrental/locateaddress.php?country=$1&city=$2&locate=$3 [QSA]

RewriteCond %{HTTP_HOST} ^demo\.example\.com/carrental$
RewriteRule (.*) carrental/([^/.]+)/([^/.]+) [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ carrental/city.php?country=$1&city=$2 [QSA]

RewriteCond %{HTTP_HOST} ^demo\.example\.com/carrental$
RewriteRule (.*) carrental/([^/.]+) [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ carrental/country.php?country=$1 [QSA]

I have 2 problems.

我有2个问题。

  1. I Want to pass special characters in my url.
    I am already try (.*) but its getting many problems. I want to pass special characters into ([a-zA-Z0-9_-]+).

    我想在我的网址中传递特殊字符。我已经尝试过(。*)但是它遇到了很多问题。我想将特殊字符传递给([a-zA-Z0-9 _-] +)。

  2. My Major Query is i have one url. When my links translate to dutch language. Url : http://demo.osiztechnologies.com/carrental/Albanië

    我的主要问题是我有一个网址。当我的链接转换为荷兰语。网址:http://demo.osiztechnologies.com/carrental/Albanië

The problem is because of Albanië. It shows a 404 error. If I change this into English it works fine.

问题在于阿尔巴尼亚。它显示404错误。如果我将其改为英语,它可以正常工作。

How can I rewrite URL's with special characters?

如何用特殊字符重写URL?

2 个解决方案

#1


1  

The %{HTTP_HOST} variable is the HTTP request's "Host:" header. It is only a hostname, no path information is given in that field. Thus:

%{HTTP_HOST}变量是HTTP请求的“Host:”标头。它只是一个主机名,该字段中没有给出路径信息。从而:

RewriteCond %{HTTP_HOST} ^demo\.example\.com/carrental$

will never match. Not sure why it's there, as the resulting rule that the condition gets applied to is wrong as well:

永远不会匹配。不知道它为什么存在,因为条件应用的结果规则也是错误的:

RewriteRule (.*) carrental/([^/.]+)/([^/.]+)/([^/.]+) [R=301,L]

Here, you are matching the entire URI (via the (.*)) and then redirecting the browser to:

在这里,您匹配整个URI(通过(。*)),然后将浏览器重定向到:

/carrental/([^/.]+)/([^/.]+)/([^/.]+)

Note those ([^/.]+). They don't get replaced with anything, that's literally where you are sending the browser.

注意那些([^ /。] +)。它们不会被任何东西取代,这就是你发送浏览器的地方。

As far as the special characters. Rob Quist is only half right. While they do get encoded by the browser into escape sequences like %C3%AB, the rewrite engine decodes them back into the unicode characters before applying any rules.

至于特殊人物。 Rob Quist只有一半的权利。虽然它们确实被浏览器编码为%C3%AB等转义序列,但在应用任何规则之前,重写引擎会将它们解码为unicode字符。

So, say you want to include ë, then your rule will look like:

所以,假设您想要包含ë,那么您的规则将如下所示:

RewriteRule ^([a-zA-Z0-9_-]+)/([ëa-zA-Z0-9_-]+)$ carrental/locateaddress.php?country=$1&city=$2 [QSA]

You can stick all the possible unicode characters you expect to be getting inbetween the square brackets, but you can just make everything match easier by using the groupings similar to the ones in the broken rule:

你可以在方括号之间插入所有可能的unicode字符,但是你可以通过使用类似于破坏规则中的分组来简化所有匹配:

RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)$ carrental/locateaddress.php?country=$1&city=$2&locate=$3 [L,QSA]
RewriteRule ^([^/.]+)/([^/.]+)$ carrental/city.php?country=$1&city=$2 [L,QSA]
RewriteRule ^([^/.]+)$ carrental/country.php?country=$1 [L,QSA]

#2


0  

That won't work. You'd need to replace them with special characters (%C3%AB in this case) in order to work.

那不行。您需要使用特殊字符(在这种情况下为%C3%AB)替换它们才能工作。

The best solution here is to make 2 words for each record - a unique SEO-URL, and the real title.

这里最好的解决方案是为每条记录制作2个单词 - 一个独特的SEO-URL和真正的标题。

Let the real title be "Albanië", and the SEO-version "albanie". Just do it for compatibilty's sake.

让真正的标题是“Albanië”,以及SEO版本“albanie”。只是为了兼容性而这样做。

EDIT: Some browsers (such as Google Chrome) may translate %C3%AB in a URL to ë and back. Too bad the actual request sent to the server is the one with %C3%AB.

编辑:某些浏览器(例如谷歌浏览器)可能会将URL中的%C3%AB转换为ë并返回。太糟糕了,发送到服务器的实际请求是%C3%AB的请求。

EG: Your browser shows: site.com/locations/Albanië

EG:您的浏览器显示:site.com/locations/Albanië

Server receives: GET locations/Albani%C3%AB

服务器收到:GET位置/ Albani%C3%AB

#1


1  

The %{HTTP_HOST} variable is the HTTP request's "Host:" header. It is only a hostname, no path information is given in that field. Thus:

%{HTTP_HOST}变量是HTTP请求的“Host:”标头。它只是一个主机名,该字段中没有给出路径信息。从而:

RewriteCond %{HTTP_HOST} ^demo\.example\.com/carrental$

will never match. Not sure why it's there, as the resulting rule that the condition gets applied to is wrong as well:

永远不会匹配。不知道它为什么存在,因为条件应用的结果规则也是错误的:

RewriteRule (.*) carrental/([^/.]+)/([^/.]+)/([^/.]+) [R=301,L]

Here, you are matching the entire URI (via the (.*)) and then redirecting the browser to:

在这里,您匹配整个URI(通过(。*)),然后将浏览器重定向到:

/carrental/([^/.]+)/([^/.]+)/([^/.]+)

Note those ([^/.]+). They don't get replaced with anything, that's literally where you are sending the browser.

注意那些([^ /。] +)。它们不会被任何东西取代,这就是你发送浏览器的地方。

As far as the special characters. Rob Quist is only half right. While they do get encoded by the browser into escape sequences like %C3%AB, the rewrite engine decodes them back into the unicode characters before applying any rules.

至于特殊人物。 Rob Quist只有一半的权利。虽然它们确实被浏览器编码为%C3%AB等转义序列,但在应用任何规则之前,重写引擎会将它们解码为unicode字符。

So, say you want to include ë, then your rule will look like:

所以,假设您想要包含ë,那么您的规则将如下所示:

RewriteRule ^([a-zA-Z0-9_-]+)/([ëa-zA-Z0-9_-]+)$ carrental/locateaddress.php?country=$1&city=$2 [QSA]

You can stick all the possible unicode characters you expect to be getting inbetween the square brackets, but you can just make everything match easier by using the groupings similar to the ones in the broken rule:

你可以在方括号之间插入所有可能的unicode字符,但是你可以通过使用类似于破坏规则中的分组来简化所有匹配:

RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)$ carrental/locateaddress.php?country=$1&city=$2&locate=$3 [L,QSA]
RewriteRule ^([^/.]+)/([^/.]+)$ carrental/city.php?country=$1&city=$2 [L,QSA]
RewriteRule ^([^/.]+)$ carrental/country.php?country=$1 [L,QSA]

#2


0  

That won't work. You'd need to replace them with special characters (%C3%AB in this case) in order to work.

那不行。您需要使用特殊字符(在这种情况下为%C3%AB)替换它们才能工作。

The best solution here is to make 2 words for each record - a unique SEO-URL, and the real title.

这里最好的解决方案是为每条记录制作2个单词 - 一个独特的SEO-URL和真正的标题。

Let the real title be "Albanië", and the SEO-version "albanie". Just do it for compatibilty's sake.

让真正的标题是“Albanië”,以及SEO版本“albanie”。只是为了兼容性而这样做。

EDIT: Some browsers (such as Google Chrome) may translate %C3%AB in a URL to ë and back. Too bad the actual request sent to the server is the one with %C3%AB.

编辑:某些浏览器(例如谷歌浏览器)可能会将URL中的%C3%AB转换为ë并返回。太糟糕了,发送到服务器的实际请求是%C3%AB的请求。

EG: Your browser shows: site.com/locations/Albanië

EG:您的浏览器显示:site.com/locations/Albanië

Server receives: GET locations/Albani%C3%AB

服务器收到:GET位置/ Albani%C3%AB