htaccess 想在不影响子域的情况下添加 www

htaccess want to add www without affecting subdomains

这是我在 htaccess 中的内容,我的所有其他页面都显示 404 错误,主页有效但没有添加 www。

<IfModule mod_rewrite.c>
RewriteEngine On

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond  !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/[R=301,L]
</IfModule>

Live site link

感谢任何帮助!我要疯了:)

这应该适合你:

RewriteEngine On

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

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond  !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/ [L]