问题更换下划线连字符用的.htaccess

编程入门 行业动态 更新时间:2024-10-28 12:20:20
本文介绍了问题更换下划线连字符用的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

虽然我已经看到了这个塞马几个帖子,我仍然有一些问题,以达到我想要的。 我的旧网址的人,如:

Although I already saw few posts about this thema, I am still having some problems to achieve what I want. My old URL's were like:

myhostname/offer/1234_Nice_Offer_Cool_Whatever_HEllyeah.htm

和很明显,我想将它们改写为:

And obviously I want to rewrite them to:

myhostname/offer/1234-nice-offer-cool-whatever-hellyeah.htm

这是在code我尝试在.htaccess。这工作正常,以取代在URL的下划线,他们没有任何的目录:

This is the code I tried in .htaccess. This works fine to replace the underscores in URL's which they don't have ANY directory:

RewriteCond %{REQUEST_URI} \.htm$ [NC] RewriteRule ^([^_]*)_+(.*)$ $1-$2 [E=underscores:Yes,N] RewriteCond %{ENV:underscores} ^Yes$ RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [R=301,L]

所以,这PAIRE规则正常工作与网址,如:

So, this paire of rules work fine with URL's like:

myhostname/1234_Some_Section_hellyeah.htm

但是当我尝试在同一$ C $下的URL,如:

But when I try the same code for URL's like:

myhostname/dir1/dir2/dir3/1234_Some_Offer_Or_Section.htm

然后,服务器使一个无限循环([N]标志的我的身影......) 基本上,我想知道以何种方式影响每个目录的URL规则,为什么我会收到这个无限循环。谢谢!

Then, the server makes an infinite loop (I figure of the [N] flag...) Basically, I would like to know in which way affects a per-directory URL to these rules and why am I getting this infinite loop. Thanks!

推荐答案

您不必N标记。要通过连字符代替下划线递归以下code将工作:

You don't need N flag. To replace underscore by hyphen recursively following code will work:

RewriteRule ^([^_]+)_(.+?\.htm)$ $1-$2 [L,NC,E=underscores:Yes] RewriteCond %{ENV:REDIRECT_underscores} ^Yes$ RewriteRule ^([^_]+)$ /$1 [R=301,L]

更多推荐

问题更换下划线连字符用的.htaccess

本文发布于:2023-10-31 18:22:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546899.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:下划线   字符   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!