为什么htaccess重定向代码无法正常工作?

时间:2019-02-04 23:29:47

标签: apache .htaccess web-services apache2

如果REQUEST_URI不是以您看到的其中一个关键字开头,但是在我的新服务器中不起作用,我可以使用此代码进行重定向!

RewriteCond "%{REQUEST_URI}" "!^/$"
RewriteCond "%{REQUEST_URI}" "!^/blog(.*)$"
RewriteCond "%{REQUEST_URI}" "!^/page(.*)$"
RewriteCond "%{REQUEST_URI}" "!^/faq(.*)$"
RewriteCond "%{REQUEST_URI}" "!^/users(.*)$"
RewriteRule "^(.*)$" "http://example.com/blog/$1" [L,R=301]

此代码可在我以前的服务器上完美运行!

通过在https://htaccess.madewithlove.be/中进行测试应该可以了!

1 个答案:

答案 0 :(得分:1)

确定要启用mod_rewrite吗? 您需要一个

{RewriteEngine on}

在您的httpd.conf中或在.htaccess中的条件/规则以上

编辑:由于注释中缺少良好的格式,因此我也在此处添加了启用mod_rewrite日志记录:

<VirtualHost *:80>
RewriteEngine On
LogLevel alert rewrite:trace6
ErrorLog "path/to/log"
ServerName .....
...
</VirtualHost>