简体   繁体   中英

How to redirect all urls to a www. subdomain

I've got this rewrite in my .htaccess:

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^domain.com/$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Which works fine for domain.com but doesn't redirect the URL with something after the /

(domain.com/something.php should redirect to www.domain.com/something.php)

How can this be done?

Thanks in advance!!

check it out

RewriteCond %{HTTP_HOST} !^www\.domain\.com 
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]

我的猜测是,因为您编写了^domain.com/$ -美元符号的末尾表示字符串的结尾,所以后面没有任何内容-这就是为什么它可以与domain.com一起使用,但是不能与其他功能一起使用吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM