Remove/Redirect index.php from url to prevent duplicate urls

后端 未结 5 1871
盖世英雄少女心
盖世英雄少女心 2021-01-03 09:56

Please read the question carefully before marking as duplicate.

We all know, that using in .htaccess:

RewriteCond %{REQUEST_FIL         


        
相关标签:
5条回答
  • 2021-01-03 10:33

    Insert these rules just below RewriteEngine On line:

    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=302,NC,NE]
    
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=302,NC,NE]
    
    0 讨论(0)
  • 2021-01-03 10:48

    This solved my problem to force https & remove index.php from the url in Kohan 2.3

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=302,NC,NE]
    
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=302,NC,NE]
    
    
    RewriteRule ^(application|system) - [F,L]
    
    RewriteCond %{THE_REQUEST} /index.php [NC]
    RewriteRule ^(.*)index\.php$ /$1/ [R=301,L,NC,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule .* index.php/$0 [PT,L]
    
    
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?!localhost$|127\.0\.0\.1$)(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
    
    0 讨论(0)
  • 2021-01-03 10:49

    After spending hours I write below code for me and its 100% working

    Redirect index.php to non index.php

    RewriteCond %{THE_REQUEST} ^.*/index\.php
    RewriteRule ^index.php/(.*)$ /$1 [R=301,L]
    
    0 讨论(0)
  • 2021-01-03 10:51

    how can I redirect in .htaccess all urls that contain index.php to to the same url without index.php?

    Add this to your .htaccess

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
    RewriteRule ^ %1 [R=301,L]
    
    0 讨论(0)
  • 2021-01-03 10:55

    For Nginx, here is the rules :

    location / {
        rewrite ^/(.*?)index\.php[^/] /$1? redirect;
        rewrite ^/(.*?)index\.php(?:/(.*))?$ /$1$2? redirect;
    }
    
    0 讨论(0)
提交回复
热议问题