1

I have got 3 cases of mod_rewrite:

http://www.domain.com/location/albania/tirana/tirana-airport
http://www.domain.com/location/albania/tirana
http://www.domain.com/location/albania

The actual url for all these cases would be:

http://www.domain.com/page.php?country=albania&city=tirana&location=tirana-airport

Can you describe a mod_rewrite rule which can work for all 3 cases? Right now if a city or location is missing, the page returns 404. It only works if all the 3 parameters are present. Heres the rule I am using right now:

RewriteRule ^location/([^/]+)/([^/]+)/([^/]+)(.*)$ page.php?country=$1&city=$2&location=$3 

Thanks in advance!

1 Answer 1

1

Replace your rule with this:

RewriteRule ^location/([^/]+)/?([^/]*)/?([^/]*)/?$ /page.php?country=$1&city=$2&location=$3 [L,QSA,NC]

It works with all 3 of your URLs.

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.