Search code examples
.htaccessmod-rewriteurl-rewriting

I need to rewrite 2 urls in htaccess to different page. Both urls start with same name but one with single parameter and the other with 2 parameter


I have 2 dynamic urls

http://localhost:8080/overseas/cost/cancer and http://localhost:8080/overseas/cost/cancer/cancer-treatment

structure is like user will click on any department (cancer, cardiology, dental etc) the url will be first url written above and in that particular department there are procedures under that department which again has a url which is second url written above. I need to maintain the url perfectly for SEO (meaning first "cost" then "department" and then "procedure")

my htaccess code is

RewriteRule ^cost/([a-zA-Z0-9-/]+)$ department.php?type=dept&dept=$1 [L]
RewriteRule ^cost/([a-zA-Z-0-9-]+)/ department.php?type=dept&dept=$1 [L]

RewriteRule ^cost/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)$ procedure.php?type=spe&dept=$1&spe=$2 [L]
RewriteRule ^cost/([a-zA-Z0-9-/]+)/([a-zA-Z-0-9-]+)/ procedure.php?type=spe&dept=$1&spe=$2 [L]

Problem with htaccess is that the second procedure rewrite rule is not working and always first department rewrite url is only working for both the urls.

I did not find any answers related to this topic over the internet. Can anybody help thanks


Solution

  • As commented by @CBroe. I placed the less specific case later and it worked. Thanks a lot