简体   繁体   中英

.htaccess RewriteRule not working for two values with same code

Doctors Code (Working)

RewriteEngine On
RewriteRule ^doctors/([0-9]+)\/([a-z]+)\/([a-z]+)\/?$ doc.php?doc_code=$1&firstname=$2&lastname=$3 [L,NC,R=301] 
RewriteRule ^doctors/([0-9]+)\/([a-z]+)\/([a-z]+)\/([a-z]+)\/?$ doc.php?doc_code=$1&firstname=$2&lastname=$3&action=$4 [L,NC,R=301] 

Pharmacy Code (Not Working)

RewriteRule ^/pharmacy/([0-9]+)\/([a-z]+)\/?$ pharmacy.php?id=$1&name=$2 [L,NC,R=301] 
RewriteRule ^/pharmacy/([0-9]+)\/([a-z]+)\/([a-z]+)\/?$ pharmacy.php?id=$1&name=$2&action=$3 [L,NC,R=301] 

When I Am Using The Code Below, It Works Fine For Pharmacy But Purpose Is Not Solved Because I Want The Link To Look As '/Pharmacy' & not '/Doctors':

 RewriteRule ^/doctors/([0-9]+)\/([a-z]+)\/?$ pharmacy.php?id=$1&name=$2 [L,NC,R=301] 
    RewriteRule ^/doctors/([0-9]+)\/([a-z]+)\/([a-z]+)\/?$ pharmacy.php?id=$1&name=$2&action=$3 [L,NC,R=301] 

The full .htacess code:

ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag None


RewriteEngine On
RewriteRule ^doctors/([0-9]+)\/([a-z]+)\/([a-z]+)\/?$ doc.php?doc_code=$1&firstname=$2&lastname=$3 [L,NC,R=301] 
RewriteRule ^doctors/([0-9]+)\/([a-z]+)\/([a-z]+)\/([a-z]+)\/?$ doc.php?doc_code=$1&firstname=$2&lastname=$3&action=$4 [L,NC,QSA] 

RewriteRule ^pharmacy/([0-9]+)/([a-z]+)/?$ pharmacy.php?id=$1&name=$2 [L,NC,QSA] 
RewriteRule ^pharmacy/([0-9]+)/([a-z]+)/([a-z]+)/?$ pharmacy.php?id=$1&name=$2&action=$3 [L,NC,QSA]

Take out leading slash and turn off MultiViews option:

Options -MultiViews

RewriteEngine On

RewriteRule ^pharmacy/([0-9]+)/([a-z]+)/?$ pharmacy.php?id=$1&name=$2 [L,NC,QSA] 
RewriteRule ^pharmacy/([0-9]+)/([a-z]+)/([a-z]+)/?$ pharmacy.php?id=$1&name=$2&action=$3 [L,NC,QSA]

Also you don't need R=301 as you don't want to show your internal URL in browsers.

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