我想将 domain.com/index.php 重定向到 domain.com


I want to redirect domain.com/index.php to domain.com

如何将 mydomainname.com/index.php 重定向到 mydomainname.com

目前我也使用以下代码。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^mydomianname'.com
    RewriteRule (.*) http://mydomianname.com/$1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s/+index'.php'?p=([^'s&]+) [NC]
    RewriteRule ^ /%1? [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
</IfModule>

应该是你完整的.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^mydomianname'.com
    RewriteRule (.*) http://mydomianname.com/$1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s/+index'.php'?p=([^'s&]+) [NC]
    RewriteRule ^ /%1? [R=301,L]
    # remove index.php
    RewriteCond %{THE_REQUEST} /index'.php [NC]
    RewriteRule ^(.*?)index'.php$ /$1 [L,R=301,NC,NE]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
</IfModule>

这个例子只适用于http,但应该大致可以解决问题。

# Redirect requests with index.php to the corresponding request
# without the index.php 
RewriteRule ^index.php(.*) http://mydomianname.com$1 [R=301,L]