我希望将根(www.example.com)重定向到index.html,但是如果index.html不存在,则重定向到index.php。
如果URL看起来(www.example.com/anything-here)会被重定向到index.php。
DirectoryIndex index.php index.html index.htm index.cgi
<IfModule mod_rewrite.c>
RewriteEngine On
## I would like the root ( www.example.com ) to be redirected to the index.html only if it has nothing behide it example : www.example.com/page-login.html or www.example.com/index.php
## I tried the code below but it is not working
RewriteRule ^/?$ index.html [L]
## The code below just rewrites for example : page-login.html to the index.php ( this code works for me )
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.css|\.js|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) %{ENV:REWRITEBASE}index.php
</IfModule>
上述代码中的某些部分有效,但其他部分不起作用。
任何帮助都会很棒。
更新已解决
我已经在下面解决了它的工作代码:
DirectoryIndex index.html index.htm index.php index.cgi
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) %{ENV:REWRITEBASE}index.php [L]
</IfModule>
以下评论使我走上了正轨;-)
谢谢Michael Berkowski