[英]How to remove .php and replace ? with / in htaccess
How do I remove .php
and replace ?
如何删除.php
并更换?
with /
at the same time.与/
同时。
I have我有
http://localhost/testingproject/testing.php?mode=getdata
I want it to be called from the browser like this:我希望从浏览器中调用它,如下所示:
http://localhost/testingproject/testing/getdata
In replacing ?
在替换?
data, I want it to be compatible with dir.数据,我希望它与 dir 兼容。
Like in dir, I have:就像在目录中一样,我有:
testing.php
user.php
dashboard.php
So, if the user calls http://localhost/testingproject/user
, alone, there is no need to parse ?
那么,如果用户单独调用http://localhost/testingproject/user
,就不需要解析了?
to /
as user
is a valid PHP file: user.php
. to /
as user
是一个有效的 PHP 文件: user.php
。
But if user the calls http://localhost/testingproject/user/abc
, then user.php
page should get $_GET['mode']
value abc
.但是如果用户调用http://localhost/testingproject/user/abc
,那么user.php
页面应该得到$_GET['mode']
值abc
。
I've searched but still cannot find compatible htaccess code.我已经搜索但仍然找不到兼容的 htaccess 代码。
I found one that works.我找到了一个有效的。 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 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.