Apache 如何在“.htaccess”中创建重定向URL的规则?

Apache 如何在“.htaccess”中创建重定向URL的规则?,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我希望发生以下重定向 example.com --> www.example.com/abc www.example.com --> www.example.com/abc example.com/abc --> www.example.com/abc example.com/anyRubbish --> www.example.com/abc 但是我对RedirectCond和ReWriteRule以及RewriteBase之间的区别感到困惑,[L,R301]中的'L

我希望发生以下重定向

example.com --> www.example.com/abc
www.example.com --> www.example.com/abc
example.com/abc --> www.example.com/abc
example.com/anyRubbish --> www.example.com/abc
但是我对RedirectCond和ReWriteRule以及RewriteBase之间的区别感到困惑,[L,R301]中的'L'和'R'等等


我正在为Apache服务器编写规则。

您可以使用以下规则:

 RewriteEngine on
 RewriteCond ℅{HTTP_HOST} !^www\. [NC,OR]
 RewriteCond ℅{REQUEST_URI} !^/ABC
 RewriteRule ^ http://www.example.com/abc℅{REQUEST_URI} [L,R]
下面是一个简短的解释:

第一个条件是重写cond℅{HTTP_HOST}^www\。[或]检查http主机头字符串是否以www开头。如果主机值为example.com,则条件返回true。 第二个条件是重写cond℅{请求_URI}^/ABC测试Uri。检查Uri是否为/ABC。如果URL为example.com/foobar,则返回true;如果URL为example.com/ABC,则返回false OR标志告诉mod rewrite执行其中一个条件,如果满足上述脚本中的一个条件,则应用规则


重写规则重写规则^http://www.example.com/abc℅{REQUEST_URI}[L,R]根据条件应用,这将把所有请求重写到www.example.com/ABC。

有关L,R NC的信息可以在这里找到