簡體   English   中英

使用.htaccess從網址中刪除尾隨/index.php

[英]Remove trailing /index.php from url using .htaccess

我正在使用PHP作為API服務器來構建一個角度應用程序。 我想清除角度post方法中的尾隨/index.php 我嘗試使用如下的.htaccess文件

    ######### Begin - RewriteEngine enabled
    RewriteEngine On
    ########## End - RewriteEngine enabled

    ########## remove index.php from the end of URI
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
    ########## 

我的網址結構如下

http://localhost/api/auth/index.php

http://localhost/api/auth一樣訪問它

現在我可以通過使用獲取帖子數據

this.http.post('/api/auth/', parameters, request.options)

但我不希望/在URL的結尾。 如何在.htaccess文件中添加此條件? 任何幫助,將不勝感激。

添加RewriteRule追加斜杠。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ /$1/ [L,R=301]

暫無
暫無

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

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