0

I have a semi-professional website about my travels where I present all the pictures for each country.

For that I have a MySQL-Database containing the following attributes: - country - country-id - pictures (links)

I am using a PHP-file which requests the pictures: "country.php"

So I get the URL-Structure: www.url.com/country/spain/ or www.url.com/country/usa/.

What I need is to change the URL Structure to www.url.com/spain but still maintain that "central" country.php-file.

I know a method which only works, when I have a folder for each Country in my webspace and an index.php-file which simply loads the country.php-file (I did that on another website). But in this case I would have way too many folders, which makes it all too complex since there are not only countries but also "special places and cities".

Is there another way to do that?

EDIT: I got it with this code:

RewriteEngine On

RewriteRule ^([a-zA-Z0-9-/]+)$ country.php?url=$1

But now the problem is, that whatever I type in, eg. www.url.com/xyz, the server thinks that I want to open the country "xyz". What can I do, to only rewrite, when the entered country is in my database?.

I am sorry if I ask too complicated, but I just didn't know how explain my problem better.

skies
  • 25
  • 5
  • Have you thought about using URL Rewrite? Also please provide a code example of what you have tried, any errors you encounter, or other information. – Twisty Apr 13 '15 at 18:32

2 Answers2

0

If you dont have any framework in use, which handles your routing, you could simply use the .htaccess file and set a rewrite rule.

Look here for example: how to remove folder name from url using htaccess

Community
  • 1
  • 1
ju_
  • 569
  • 1
  • 4
  • 17
  • Thank you for your help. The problem is, that I don't have a folder. I have a php-file (country.php) which takes information from the database depending on the entered url. – skies Apr 14 '15 at 18:43
0
$url ="******YOUR URL HERE***********";
$urlArr = parse_url($url);
$urlbase = $urlArr['host'] . @$urlArr['path']; 
Thanasis
  • 329
  • 4
  • 8