无效的命令' RedirectMatch' - Apache 2.47。 Ubuntu Trust

时间:2016-01-12 23:46:51

标签: apache .htaccess ubuntu

我有一个.htaccess文件,如下所示,我收到错误 Invalid command 'RedirectMatch', perhaps misspelled or defined by a module not included in the server configuration。我已经做了很多搜索,无法找到问题所在,mod重写被加载,看起来似乎正在工作。

我在Ubuntu 14.04上运行Apache 2.4.7。

任何帮助或指导都会很棒。

# rewrite rules
<IfModule mod_rewrite.c>

# enable awesome urls. i.e.:
# http://yourdomain.com/about-us/team
RewriteEngine on

# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder.
# Otherwise links or the entire site will break.
#
# If your homepage is http://yourdomain.com/mysite
# Set the RewriteBase to:
#
# RewriteBase /mysite
#
RewriteBase /

# force www on domain
# RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
# RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

# block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L]

# block all files in the site folder from being accessed directly
RewriteRule ^site/(.*) error [R=301,L]

# block all files in the kirby folder from being accessed directly
RewriteRule ^kirby/(.*) error [R=301,L]

# leave robots.txt alone for search engines
RewriteRule ^robots.txt robots.txt [L]

# redirect /cashback to home
RedirectMatch 301 ^/cashback/?$ http://www.example.com/

# add trailing slash to links
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

# make panel links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]

# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]

</IfModule>

由于

1 个答案:

答案 0 :(得分:1)

  

加载了mod重写,看起来似乎正常工作   RedirectMatch 301 ^/cashback/?$ http://www.example.com/

RedirectMatch是mod_alias的一部分,而不是mod_rewrite。虽然mod_alias通常默认加载,除非它被专门删除?

但是,您不应该混合使用mod_alias和mod_rewrite重定向。由于它们属于不同的模块,因此它们在不同的时间执行(mod_rewrite通常是第一个),因此您可能会遇到意外的冲突。由于您已经将mod_rewrite用于其他所有内容,因此您应该使用mod_rewrite(即。RewriteRule)重新编写此重定向。像这样:

RewriteRule ^cashback/?$ / [R=301,L]