htaccess non-www. to www redirect AND request rewrite to index.php

前端 未结 1 896
醉酒成梦
醉酒成梦 2021-01-17 01:53

Trying to combine two htaccess RewriteRules at the same time:

1) transform all non-www URLs to www
2) send all requests to index.php

Number 2 works with

相关标签:
1条回答
  • 2021-01-17 02:20

    It looks like you just need to add the HTTP_HOST checking before the catch-all rewrite to index.php.

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

    This redirects to www before any of the URI have been rewritten to the catch-all, then:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [QSA]
    

    Do the catch-all, which happens after the non-www gets 301 redirected to the www domain.

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