.htaccess Redirect non-WWW to WWW preserving URI string

后端 未结 3 445
情歌与酒
情歌与酒 2020-12-03 01:51

I\'m running the CodeIgniter platform, which uses .htaccess to accept URLs like

http://www.mysite.com/controller/function/argument

I curren

相关标签:
3条回答
  • 2020-12-03 02:30

    If you are on apache 2.4 ,You can use the following simple redirect :

    <if "%{HTTP_HOST} =='example.com'">
    Redirect / http://www.example.com/
    </if>
    
    0 讨论(0)
  • 2020-12-03 02:41

    It should be something like this:

    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    
    0 讨论(0)
  • 2020-12-03 02:44

    I had a similar problem, and this .htaccess works for me

    RewriteEngine On                           
    
    #This bit rewrites your host name to include www
    RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L]
    
    #This bit does the codeigniter magic
    RewriteCond %{REQUEST_FILENAME} !-f  
    RewriteCond %{REQUEST_FILENAME} !-d  
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    0 讨论(0)
提交回复
热议问题