简体   繁体   中英

.htaccess to pass parameters and remove the page name

I have the following folder structure in my website:

     example.com/
                reports/
                        causelist/
                                 final_causelist.php

I have a link / URL to the final_causelist.php page is as:

http://example.com/reports/causelist/final_causelist.php?wb_sno=23&dated=2020-10-26&j_names=Mr.+ABC

I want to access the page like the following:

http://example.com/23/2020-10-26/Mr.+ABC

For the above, I created .htaccess in the causelist folder with the following code:

RewriteEngine on  
RewriteBase /reports/causelist/
Options -Indexes

RewriteRule ^(\d+)/([a-z-]+)/(.+)/$ /final_causelist.php?wb_sno=$1&dated=$2&j_names=$3 [L,B]

But it does not show the page and complaint that the requesting page is not found on this server?

Your regex is not matching date part correctly and you must remove leading / from target as you're using a RewriteBase .

Options -Indexes
RewriteEngine on
RewriteBase /reports/causelist/

RewriteRule ^(\d+)/([\d-]+)/(.+?)/?$ final_causelist.php?wb_sno=$1&dated=$2&j_names=$3 [L,QSA]

Could you please try following.

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(\d+)/(\d{4}-\d{2}-\d{2})/(.+?)/?$
RewriteRule ^.*$ /reports/causelist/final_causelist.php?wb_sno=%1&dated=%2&j_names=%3 [QSA,NE,NC,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