如何将此 Apache Rewrite 规则转换为 Tuckey UrlRewriteFilter 规则?

发布于 2024-09-18 06:48:59 字数 881 浏览 4 评论 0原文

我有以下 Apache Rewrite 规则

<IfModule rewrite_module>
     RewriteEngine on
     RewriteMap tolowercase int:tolower
     RewriteCond $2 [A-Z] 
     RewriteRule ^(.*)/(.*).html$ $1/${tolowercase:$2}.html [R=301,L]
</IfModule>

可以更改此设置:

http://localhost.localdomain.com/FooBarBaz.html

对此:

http://localhost.localdomain.com/foobarbaz.html

我想将其移植到此 tuckey.org URL重写过滤器

我可以使用什么等效规则来使 URL 小写?我对如何形成条件元素特别感兴趣。

这是我对规则的第一次修改,但即使没有条件,它也不起作用:

<rule>
    <name>Force URL filenames to lower case</name>
    <from>^(.*)/(.*).html$</from>
    <to type="permanent-redirect" last="true">$1/${lower:$2}.html</to>
</rule>

I have the following Apache Rewrite rule

<IfModule rewrite_module>
     RewriteEngine on
     RewriteMap tolowercase int:tolower
     RewriteCond $2 [A-Z] 
     RewriteRule ^(.*)/(.*).html$ $1/${tolowercase:$2}.html [R=301,L]
</IfModule>

that changes this:

http://localhost.localdomain.com/FooBarBaz.html

to this:

http://localhost.localdomain.com/foobarbaz.html

I'd like to port it to this tuckey.org URL Rewrite Filter.

What is an equivalent rule that I could use to make the URL lowercase? I'm particularly interested in how to form the condition element.

Here's my first cut at the rule, but it doesn't work, even without the condition:

<rule>
    <name>Force URL filenames to lower case</name>
    <from>^(.*)/(.*).html
lt;/from>
    <to type="permanent-redirect" last="true">$1/${lower:$2}.html</to>
</rule>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

○愚か者の日 2024-09-25 06:49:05

Sean,

您不需要条件来执行此操作(除了忽略 AJAX 调用)。更重要的是,条件元素 不区分大小写属性,只有 from 元素才具有。一旦我意识到这一点,我就能够将规则编写为:

<rule match-type="regex">  
    <note>Force URL to lower case</note>
    <from casesensitive="true">^.*[A-Z].*
lt;/from>
    <to type="permanent-redirect" last="true">${lower:$0}</to>  
</rule>

注意:这适用于整个路径请求(尽管不适用于查询字符串)。

我偶然发现了你的帖子,因为我得到的 URL 重写过滤器规则看起来很像你的规则,但不起作用。经过大量的试验和错误,我最终发现问题根本不在于正则表达式。它匹配,但区分大小写,所以我得到了无限的重定向。

Sean,

You don't need a condition to do this (excepting the ignore on the AJAX calls). More importantly, the condition element does not have a casesensitive attribute, only the from element does. Once I realized this, I was able to write the rule as:

<rule match-type="regex">  
    <note>Force URL to lower case</note>
    <from casesensitive="true">^.*[A-Z].*
lt;/from>
    <to type="permanent-redirect" last="true">${lower:$0}</to>  
</rule>

NOTE: This works for the entire path request (though not the querystring).

I stumbled across your post because the URL Rewrite Filter rule I was given that looked a lot like yours was not working. Through a ton of trial and error, I eventually found that the problem wasn't with the regular expression at all. It was that it was matching but was not case sensitive, so I was getting infinite redirects.

枫林﹌晚霞¤ 2024-09-25 06:49:03

这是我最终决定的:

<rule match-type="regex">
    <name>Force URL filenames to lower case</name>
    <condition type="request-uri" casesensitive="false" operator="notequal">^.*/a4j.*
lt;/condition>
    <condition type="request-uri" casesensitive="true">^.*/.*[A-Z].*.html
lt;/condition>
    <from>^(.*)/(.*).html
lt;/from>
    <to type="permanent-redirect" last="true">$1/${lower:$2}.html</to>
</rule>

第一个条件是防止规则在 A4J AJAX 请求上运行。

Here's what I eventually settled on:

<rule match-type="regex">
    <name>Force URL filenames to lower case</name>
    <condition type="request-uri" casesensitive="false" operator="notequal">^.*/a4j.*
lt;/condition>
    <condition type="request-uri" casesensitive="true">^.*/.*[A-Z].*.html
lt;/condition>
    <from>^(.*)/(.*).html
lt;/from>
    <to type="permanent-redirect" last="true">$1/${lower:$2}.html</to>
</rule>

The first condition is to prevent the rule from running on A4J AJAX requests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文