how to modify .htaccess file to always redirect to www

后端 未结 4 1844
灰色年华
灰色年华 2020-12-09 05:05

I would like to modify my .htaccess file so that when someone comes into my site without typing www the site always redirects them to the www version. For example, if my ur

相关标签:
4条回答
  • 2020-12-09 05:30

    If you want redirect example.com to www.example.com you can try below code

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !www.example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
    
    0 讨论(0)
  • 2020-12-09 05:33

    There are two methods available

    1) use mod_alias apache module

    Redirect permanent /something http://yourwebsite.com/something

    2) Add the following entry in your .htaccess / http.conf / yourwebsite.conf in the webserver configuarion directory

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

    0 讨论(0)
  • 2020-12-09 05:35

    Add something like this immediately after RewriteEngine on:

    RewriteCond %{HTTP_HOST} ^example\.com$
    RewriteRule ^(.*) http://www.example.com/$1 [R=301]
    
    0 讨论(0)
  • 2020-12-09 05:47

    I use the code below. It can be used for any domain name. You just need to enter it in your .htaccess file.

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

    (edited to have all the code in the same block)

    0 讨论(0)
提交回复
热议问题