1

I am using .htaccess file to achieve clean urls ,But issue is , I am unable to get 2nd parameter.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-zA-Z0-9]+)$ result-by-city.php?city=$1

RewriteRule ^\/(searedness)([0-9]+)(.*)-gu([0-9]+)\/(.*)$ ?searedness$2=$4&%{QUERY_STRING}[L]

</IfModule>

If I add second parameter like this

RewriteRule ^([a-zA-Z0-9]+)$ result-by-city.php?city=$1&location=$2

then , page goes 404

http://example.com/delhi/noida --> returns 404

http://example.com/delhi/ --> working fine with below rule only

RewriteRule ^([a-zA-Z0-9]+)$ result-by-city.php?city=$1
8
  • You only have one group in the last pattern, but you reference two with $1 and $2, what do you intend to have there? Commented Jun 20, 2018 at 7:58
  • I did not understand your question. ' One group in the last pattern ' means ? Sorry but i have very little knowledge about regex. Commented Jun 20, 2018 at 8:02
  • RewriteRule ^([a-zA-Z0-9]+)$ result-by-city.php?city=$1 works because $1 refers to the value captured with the first parenthesized construct in the regex pattern. You do not have the second (...) there. Commented Jun 20, 2018 at 8:04
  • RewriteRule ^([a-zA-Z0-9]+)$ ^([a-zA-Z0-9]+)$ result-by-city.php?city=$1&location=$2 like this ? It is showing 500 internal server error Commented Jun 20, 2018 at 8:07
  • Of course, it is not correct. Do you want to match 2 subparts? Try ^([^/]+)/([^/]+)/?$ Commented Jun 20, 2018 at 8:11

1 Answer 1

2

You may use this rule for :city/location/speciality

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)(?:/([^/]+)(?:/([^/]+))?)?/?$ page.php?city=$1&location=$2&speciality=$3 [L,QSA]

This single rule will support all of these URILs:

example.com/delhi
example.com/delhi/noida 
example.com/delhi/noida/dentist
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.