簡體   English   中英

使用.htaccess從URL中刪除/index.php/

[英]Remove /index.php/ from the URL with .htaccess

需要注意的是,我在StackOverflow上發現了類似的問題,但是它們並沒有按照我的要求工作。

我有一個網址,例如:

http://www.example.com/index.php/test

我想刪除index.php目錄,因此如果輸入以上內容,它將轉到:

http://www.example.com/test

這似乎起作用

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]

但是,如果網址是:

http://www.example.com/index.php?option=example

變成

http://www.example.com/?option=example

因此,僅當index.php是與我的第一個示例一樣的目錄時,才應將其刪除。

另外,如果您輸入例如:

http://www.test.example.com/index.php/index.php/dfd

應該去

http://www.test.example.com/dfd

以下規則將:

  • 不申請/index.php?o=a

  • /index.php/index.php/dfd重定向到/dfd

  • /index.php/index.php/dfd?a=b重定向到/dfd?a=b

  • /index.php/index.php?a=b重定向到/index.php?a=b

RewriteCond %{QUERY_STRING} .+  
RewriteRule ^index\.php(/index\.php)+/?$ /index.php [R=302,L,QSA,NC]

RewriteCond %{QUERY_STRING} ^$ [OR]
RewriteCond %{REQUEST_URI} !index\.php/?$
RewriteRule ((^|/)index\.php)+/?(.*)$ /$3 [R=302,L,QSA,NC]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM