Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:07:26+00:00 2026-05-28T22:07:26+00:00

I have a site where articles being submitted from worldwide and I record the

  • 0

I have a site where articles being submitted from worldwide and I record the location of them as Country -> State -> City, for that I am generating URLs like:

site/location/countryname/statename/cityname

I have a single php file which can take care of coming request and gets values in query string, now the problem is how to write mod_rewrite so it can have URL like above?

PS: It should not pass empty values if someone deletes the statename or countryname, means URL can be:

site/location/countryname
site/location/countryname/statename
site/location/countryname/statename/cityname

But can not be:

site/location//statename/cityname
site/location/countryname//cityname

In above urls if countryname is deleted then statename shouldnt be treated as countryname. Reading file name is location.php

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:07:27+00:00Added an answer on May 28, 2026 at 10:07 pm

    Ok I have got a way to do that:

    RewriteRule ^bylocation/([-a-z_]+)(?:/([-a-z_]+)(?:/([-a-z_]+))?)?/?$ location.php?country=$1&state=$2&city=$3 [NC,L,QSA]
    

    This single rule can take care, instead of three rules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my site as localhost/tutorials/rewrite/news.php on this page are titles from news articles
I currently have a site with multiple articles being user-generated as content. On each
I have a asp.net mvc site that being hosted via IIS 7. I believe
Hi I have a site that I have launched and my news articles are
I have a wordpress site that I moved from domain.info to domain.com. Some of
I have articles on my site, and I would like to add tags which
I have several articles on a Joomla (1.5) site. These articles are public --
I have a Joomla 1.5 site. I have articles in my site with different
I have a problem with my site. The site has multiple entities: Articles, Posts,
For example I have site http://localhost/site In IIS I set that 404 error causes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.