简体   繁体   English

替换URL中的字符时,htaccess 301重定向-Helicon ASAPI ReWrite模块

[英]htaccess 301 redirect while replacing characters in URL - Helicon ASAPI ReWrite module

I have an old site that is being rebuilt. 我有一个正在重建的旧站点。 Instead of using a folders structure, it is using sub-domains. 它不是使用文件夹结构,而是使用子域。 The segments are different, but the redirect itself is pretty simple. 这些段是不同的,但是重定向本身非常简单。 I can handle it like so: 我可以这样处理:

RewriteRule ^segment/blog/view$ http://blogs.site.com/segment/article [R=301,NE,NC,L]
RewriteRule ^segment/blog$ http://blogs.site.com/segment [R=301,NE,NC,L]

So if I had www.site.com/segment/blog, it will now go to blogs.site.com/segment. 因此,如果我拥有www.site.com/segment/blog,现在它将转到blogs.site.com/segment。 If I had www.site.com/segment/blog/view/catchy_name_goes_here, currently it redirects it to blogs.site.com/segment/article/catchy_name_goes_here and I NEED it to go here: blogs.site.com/segment/article/catchy-name-goes-here. 如果我有www.site.com/segment/blog/view/catchy_name_goes_here,目前它会将其重定向到blogs.site.com/segment/article/catchy_name_goes_here,我需要将其转到此处:blogs.site.com/segment/article / catchy-name-goes-here。

My issue comes from a decision to change the separator in the URI. 我的问题来自决定更改URI中的分隔符。 The old articles were built with underscores '_' and the new articles are built with hyphens '-'. 旧文章使用下划线“ _”构建,新文章使用连字符“-”构建。

How can I replace the underscores in the article titles with hyphens? 如何用连字符替换文章标题中的下划线?

Try these rules: 尝试以下规则:

RewriteRule ^/segment/blog$ http://blogs.site.com/segment [R,I,L]

# replace _ by - repeatedly
RewriteRule ^(/segment/blog/view)/([^_]*)_+(.*)$ /$1/$2-$3 [I,N,U]

# all _s gone, now do a redirect
RewriteRule ^/segment/blog/view/([^_]+)$ http://blogs.site.com/segment/article/$1  [R,I,L,U]

I ended up having to use the following. 我最终不得不使用以下内容。 I don't know how many people this might effect due to the unique settings for this site in particular, but thought I would post the answer so it could help anyone that might need it. 我不知道由于这个站点的独特设置,这可能会影响多少人,但我想我会发布答案,以便对可能需要它的任何人提供帮助。

The full settings on this are a server running IIS with Server 2k. 完整的设置是一台运行IIS和Server 2k的服务器。 The site consists of several static content pages, vb script, classic ASP, dot Net, and this is all intertwined with ExpressionEngine pages. 该站点由几个静态内容页面,vb脚本,经典ASP,点网组成,并且所有这些都与ExpressionEngine页面交织在一起。 It's a mess to say the least. 至少可以说是一团糟。 To top it off, Helicon Tech's ASAPI Rewrite Module version 3 is running on the server for .htaccess usage. 最重要的是,Helicon Tech的ASAPI重写模块版本3正在服务器上运行以用于.htaccess。 No sub-expressions, groupings, etc. were taking or being followed/processed. 没有子表达式,分组等正在被采用或遵循/处理。 The index.php rule was getting bypassed as well. index.php规则也被绕过。

This all said, I ended up with the following which parsed everything I needed. 综上所述,我得到了以下内容,这些内容解析了我所需的一切。

RewriteRule ^index.php/segment/blog/view/([^_]*)_+(.*)$ http://www.site.com/index.php/segment/blog/view/$1-$2 [R,NC]
RewriteRule ^index.php/segment/blog/view/([^_]*)$ http://blogs.site.com/segment/article/$1  [R=301,I,L,U]
RewriteRule ^segment/blog$ http://blogs.site.com/segment [R=301,NE,NC,L]
RewriteRule ^/segment/blog$ http://blogs.site.com/segment [R,I,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM