简体   繁体   中英

How to rewrite a subfolder in the URL to a PHP get parameter

I am making a webpage that uses one template HTML page and uses PHP to fill in the rest from JSON files.

I am trying to find out how I can rewrite a URL from .../project/jsonfilename/ to .../project/index.php?f=jsonfilename .

I have tried to use the following code in a .htaccess file:

RewriteEngine on
RewriteRule ^project\/([^\/]+)\/?  /index.php?f=$1

But this passes "index.php" as the argument instead of the subfolder I want.

Check this rule in your .htaccess file (for /project/jsonfilename/ <> /project/index.php?f=jsonfilename)

RewriteEngine On
RewriteBase /

RewriteRule ^project\/(.*)\/$ /project/index.php?f=$1 [L]

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