doubanduo7620 2019-03-14 04:35
浏览 80
已采纳

htaccess从url /文件夹中删除index.php

I have a problem and couldn't find a working solution on the internet. So hopefully you can help me.

I need to make my website as SEO friendly as possible. Therefore I need to change the following

https://www.example.com/index.php
https://www.example.com/folder/index.php
https://www.example.com/folder/folder/index.php

To:

https://www.example.com/
https://www.example.com/folder/
https://www.example.com/folder/folder/

I need some kinda canonical redirect so that my website is only accessible without the /index.php in order to eliminate duplicate content.

I would like to use .htaccess. Any help is very much appreciated. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongpa9277 2019-03-14 05:42
    关注

    Just create .htaccess in the main domain (www.example.com/) and put below code.

    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
    RewriteRule ^ /%1 [R=301,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?