我认为.htaccess不会起作用语法问题

时间:2014-02-09 14:48:06

标签: apache .htaccess mod-rewrite

我在.htaccess文件中有这段代码:

 RewriteEngine On
 RewriteBase /
 RewriteCond %{HTTP_USER_AGENT} (mozilla|navigator|chrome) [NC]
 RewriteRule .* /newplace/ [L]

对于那些使用上面列出的浏览器的人来说,我希望从public_html中获取内容,以显示来自其他位置的内容。 现在,问题出在第四行,我不知道如何使它工作...... Anyhelp请...

我仍然存在问题,因为我提出了500个内部服务器错误....

2 个答案:

答案 0 :(得分:0)

您将每个请求重定向到文件夹/newplace/。你想要这样的东西

RewriteRule (.*) /newplace/$1 [L]

$1部分将使用您规则中的匹配。

答案 1 :(得分:0)

您的代码将导致循环,因为它会针对列出的浏览器重定向到/newplace/

试试这段代码:

 RewriteEngine On
 RewriteBase /

 RewriteCond %{HTTP_USER_AGENT} (mozilla|navigator|chrome) [NC]
 RewriteRule ^((?!newplace/).*)$ /newplace/$1 [L,NC]