问题
I have the following code to force WWW in url
rewriteCond %{HTTP_HOST} !^www.example.com [NC]
rewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I want to add a subdomain max.example and refer to www.example.com/update/max directory If I do not add any rule, max.example.com will redirect to www.example.com/update/max . If I remove force WWW in url it works. But I still need force WWW in url. How to write the rule?
Thanks!
回答1:
Change your rule to this:
RewriteCond %{HTTP_HOST} !^(www|max)\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]
来源:https://stackoverflow.com/questions/12102786/how-to-add-subdomain-in-htaccess-and-force-www-in-url