重写301 index.php到/ on htaccess不起作用

时间:2016-03-04 15:03:35

标签: .htaccess redirect mod-rewrite

我正在尝试使用index.php / index.html重定向到/但是当我在顶部添加此代码时:

RewriteRule ^index.(php|html|htm)$ / [R=301,L]
RewriteRule ^([a-z0-9-_]+)/index.(php|html|htm)$ /$1/ [R=301,L]

我当前的代码不起作用:

Options FollowSymLinks
RewriteEngine On

#301

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


#STRONA

#Pojedyncza Oferta - jezyki
RewriteRule ^([a-zA-Z]{2})/(.*)/(.*)/(.*).html$ index.php?lang=$1&page=$2&bookmarkTitle=$3&title=$4 [L]

#Aktualnosci, Oferta i Galeria - jezyki
RewriteRule ^([a-zA-Z]{2})/(.*)/(.*).html$ index.php?lang=$1&page=$2&bookmarkTitle=$3 [L]

#Linki - jezyki
RewriteRule ^([a-zA-Z]{2})/(.*).html$ index.php?lang=$1&page=$2 [L]

#Pojedyncza Oferta
RewriteRule ^(.*)/(.*)/(.*).html$ index.php?page=$1&bookmarkTitle=$2&title=$3 [L]

#Aktualnosci, Oferta i Galeria
RewriteRule ^(.*)/(.*).html$ index.php?page=$1&bookmarkTitle=$2 [L]

#Linki
RewriteRule ^([a-zA-Z]{2})/$ index.php?lang=$1 [L]
RewriteRule ^(.*).html$ index.php?page=$1 [L]

<FilesMatch "\.(htm|html|php)$">
    <IfModule mod_headers.c>
        BrowserMatch MSIE ie
        Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
    </IfModule>
</FilesMatch>
ErrorDocument 404 /404.php

添加上面的代码后,我得到了: domain.pl/page?kontakt而不是domain.pl/kontakt.html

怎么做?

1 个答案:

答案 0 :(得分:2)

index行下面RewriteEngine On删除时使用此规则:

# remove index.php or index.html
RewriteCond %{THE_REQUEST} /index\.(php|html?) [NC]
RewriteRule ^(.*)index\.(?:php|html?)$ /$1 [L,R=302,NC,NE]