如何redirect从no-www到www的所有内容除了less数文件,使用.htaccess?

如何使用.htaccessredirect从no-www到www 除了几个文件以外的所有东西?

我正在使用下面的.htaccessredirectno-www到www。

的.htaccess

Options +FollowSymlinks RewriteEngine on rewritecond %{http_host} ^[^.]+\.[^.]+$ [nc] rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,nc] 

如何为less量文件添加exception?
例如:
1)example.com/page1.html不应该被redirect到www.example.com
2)example.com/xml/page2.xml不应该被redirect到www.example.com

除example.com/page1.html和example.com/xml/page2.xml以外的所有内容应redirect到www.example.com

你可以链接你的RewriteCond指令,例如:

 RewriteEngine on RewriteCond %{REQUEST_URI} ! ^/page1\.html$ RewriteCond %{REQUEST_URI} ! ^/xml/page2\.xml$ RewriteCond %{http_host} ^[^.]+\.[^.]+$ [nc] RewriteRule ^(.*)$ http://www.%{http_host}/$1 [r=301,nc]