.htaccess redirect root to index.php

后端 未结 3 1251
萌比男神i
萌比男神i 2021-01-04 10:08

I need to redirect from http://example.com/ to http://example.com/index.php.

相关标签:
3条回答
  • 2021-01-04 10:48

    Just to add my own solution, since the answer of Michael did not work for me, I did something like:

    RewriteEngine on
    
    # These two lines redirect non-www to www.
    RewriteCond %{HTTP_HOST} ^example\.com$
    RewriteRule (.*) https://www.example.com$1 [R=301,L]
    
    # These two lines redirect the root to index.html.
    RewriteRule ^$ /index.html [R=301,L]
    RewriteRule ^/$ /index.html [R=301,L]
    

    This also preserves any possible existing query string parameters.

    0 讨论(0)
  • 2021-01-04 10:58

    Use this:

    DirectoryIndex index.php
    
    0 讨论(0)
  • 2021-01-04 10:58

    Try this:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} ^$
    RewriteCond %{HTTP_HOST} ^example.com$
    RewriteRule ^$ http://example.com/index.php [L,R=301]
    
    0 讨论(0)
提交回复
热议问题