htaccess rule redirect non www to www - litespeed server

风格不统一 提交于 2019-12-23 05:59:57

问题


I have a question about using htaccess in my litespeed server. I tried to redirect http://domain.com to http://www.domain.com using this rule:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule .* http://www.domain.com/ [L,R=301]

When I check http://domain.com using Xenu, the result is as follow:

http://domain.com/   200 ok text/html 301 Moved Permanently 
http://domain.com/%s  200 ok text/html 301 Moved Permanently  
http://www.litespeedtech.com/ 200 ok text/html LiteSpeed Web Server 
http://www.domain.com/         200 ok text/html redir 

I wonder whether I had incorrect htaccess rule or this is because of bug in litespeed? I have searched anywhere for hours...Thanks


回答1:


You can redirect non-www subdomains to the www subdomain with this rewrite:

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



回答2:


@mipadi: I guess it is not 301 redirected (or is it?). Here is what I got from Xenu:

http://domain.com/   200 ok text/html Homepage
http://cdn.domain.com/css/style.css  200 ok text/css
http://www.domain.com/about/         200 ok text/html About
http://www.domain.com/contact/         200 ok text/html Contact


来源:https://stackoverflow.com/questions/3008080/htaccess-rule-redirect-non-www-to-www-litespeed-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!