簡體   English   中英

如何刪除.php 並更換? 與 / 在 htaccess

[英]How to remove .php and replace ? with / in htaccess

如何刪除.php並更換? /同時。

我有

http://localhost/testingproject/testing.php?mode=getdata

我希望從瀏覽器中調用它,如下所示:

http://localhost/testingproject/testing/getdata

在替換? 數據,我希望它與 dir 兼容。

就像在目錄中一樣,我有:

testing.php
user.php
dashboard.php

那么,如果用戶單獨調用http://localhost/testingproject/user ,就不需要解析了? to / as user是一個有效的 PHP 文件: user.php

但是如果用戶調用http://localhost/testingproject/user/abc ,那么user.php頁面應該得到$_GET['mode']abc

我已經搜索但仍然找不到兼容的 htaccess 代碼。

我找到了一個有效的。 Now, i can call http://localhost/testproject/backend/user/abc instead of http://localhost/testproject/backend.php?mode=abc In Replace GET variables with slashes .htaccess

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^/]+)/?$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?mode=$2 [L,QSA]

暫無
暫無

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

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