添加重写规则 [英] Add rewrite rule

查看:122
本文介绍了添加重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的.htaccess在我/论坛/目录。现在,我要添加另一个规则:与来自这两个规则中指定的不同的格式的所有URL都从old-domain.com/forum/*重定向到new-domain.com/forum /.

I've this .htaccess in my /forum/ directory. Now I want to add another rule: all URLs with a format different from the ones specified in these two rules have to be redirected from old-domain.com/forum/* to new-domain.com/forum/.

我需要一个永久重定向。

I need a permanent redirect.

希望重定向的例子:

from old-site.com/forum/members/15-username
to new-site.com/forum/

实际的.htaccess:

Actual .htaccess:

RewriteEngine On
RewriteBase /forum/

RewriteCond %{HTTP_HOST} ^(?:www\.)?old-domain\.com$ [NC]
RewriteRule ^([^/]+)/([^-]+)-([^/]+)/?$ http://new-domain.com/forum/$1/$3.$2 [L,R=302,NE]

RewriteCond %{HTTP_HOST} ^(?:www\.)?old-domain\.com$ [NC]
RewriteRule ^([^-]+)-([^/]+)/?$ http://new-domain.com/forum/$2.$1 [L,NE,R=302]

仅供参考,这些规则是这些重定向: 1)

FYI, these rules are for these redirects: 1)

From: old-domain.com/forum/idF-forum-name
To: new-domain.com/forum/forum-name.idF

其中IDF是变量数,原始名称是变量短语

Where idF is a variable number, and "original-name" is a variable phrase

2)

From: old-doimain.com/forum/idF-forum-name/idT-thread-name
To: new-domain.com/forum/idF-forum-name/thread-name.idT

其中IDP是一个随机数。

Where idP is a random number.

推荐答案

您可以在底部尝试一个新的规则:

You can try a new rule at bottom:

RewriteEngine On
RewriteBase /forum/

RewriteCond %{HTTP_HOST} !^(?:www\.)?old-domain\.com$ [NC]
RewriteRule ^ - [L]

RewriteRule ^[\w-]+/\d+-[^/]+/?$ http://new-domain.com/forum/ [L,R=302]    

RewriteRule ^([^/]+)/([^-]+)-([^/]+)/?$ http://new-domain.com/forum/$1/$3.$2 [L,R=302,NE]

RewriteRule ^([^-]+)-([^/]+)/?$ http://new-domain.com/forum/$2.$1 [L,NE,R=302]

RewriteRule ^ http://new-domain.com/forum/ [L]

这篇关于添加重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆