虽然我已经看到了这个塞马几个帖子,我仍然有一些问题,以达到我想要的。 我的旧网址的人,如:
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
发布评论