简体   繁体   中英

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

How do I remove .php and replace ? 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.

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 ? to / as user is a valid PHP file: user.php .

But if user the calls http://localhost/testingproject/user/abc , then user.php page should get $_GET['mode'] value abc .

I've searched but still cannot find compatible htaccess code.

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM