2010-08-13 107 views
0

这是我的.htaccess,我想将我的domain.com重写为www.domain.com。我怎样才能做到这一点?apache url用htaccess重写

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|xml|txt)$ 
RewriteCond %{REQUEST_URI} !example/ 
RewriteRule ^(.*)$ index.php?q=$1 [QSA] 

感谢

+1

可能重复:http://stackoverflow.com/questions/1685962/htaccess-redirect-non-www-to-www-preserving-uri-string – jasonbar 2010-08-13 07:42:53

+0

真。第二个对我很好。谢谢。 (我还没有找到它。) – 2010-08-13 09:55:11

回答

3
Rewritecond %{HTTP_HOST} !www.domain.com 
RewriteRule ^/(.*)$ http://www.domain.com/$1 [L,R=301] 
+0

伟大的解决方案,不幸的是我已经知道这一点,但它不适用于我的重写。 我需要所有的链接去索引文件。像:http://www.domain.com/Oinon'和'http:// www.domain.com/whatdoyoulike/elephants'全部打开'root/index.php' – 2010-08-13 09:20:45

+0

@marharépa,如果你使用这个条件并且在你的索引重写之前进行规则,它应该完全做到这一点。 – jasonbar 2010-08-13 15:07:07