从www重定向中排除htaccess中的文件夹

时间:2014-11-28 10:20:54

标签: regex apache .htaccess mod-rewrite redirect

我的.htaccess中有一个www重定向:

RewriteCond %{HTTP_HOST} example\.com
RewriteRule ^(.*)$ http://www.example/ [R=permanent]

现在我想排除一个文件夹以使用上面的重定向。 我想访问一个文件夹,而不是用www重定向到域。 例如: 我想要的是:example.com/test 会发生什么:www.example.com/test

我可以只排除文件夹测试吗?

1 个答案:

答案 0 :(得分:1)

您可以使用:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule !^test/ http://www.%{HTTP_HOST}/%{REQUEST_URI} [L,NC,NE,R=302]

请确保此规则是RewriteEngine On下方根据您的根.htaccess(/test/上方一个目录级别)的第一条规则。

相关问题