1

如何将 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>
4

2 回答 2

1

这应该是你的完整.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>
于 2013-11-03T08:49:52.160 回答
0

此示例仅适用于 http,但应该大致可以解决问题。

# Redirect requests with index.php to the corresponding request
# without the index.php 
RewriteRule ^index.php(.*) http://mydomianname.com$1 [R=301,L]
于 2013-11-03T06:16:18.083 回答