As I don’t know how is your folder structure and how you are identifying the name of the artist and etc. I will leave a simple answer but you can adapt.
Structure of the Folder:
.
├── artists
│ ├── albums.php
│ ├── biography.php
│ └── index.php
└── index.php
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule artists/(.*)(?:/(.*))? /artists/index.php?artist=$1&page=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php [L]
In the first rule of rewrite we define - through the regex -, that all access in http://www.example.com/artists/...
should be redirected to the folder artists/index.php
with the parameters defined.
Explaining the Regex:
artists/(.*)(?:/(.*))?
└───┬──┘└─┬─┘└──┬────┘
│ │ └──────── Captura o nome da página. O `?` indica que ele é opcional.
│ └────────────── Captura o nome do artista
└──────────────────── Base
Artists/index.php
<?php
$artist = $_GET["artist"] ?? false;
$page = $_GET["page"] ?? "albums";
if ( $artist ) {
$model = new ArtistModel();
if( $model->has($artist) ) {
switch ($page) {
case "biography":
$content = $model->getBiography();
require_once "biography.php";
break;
case "albums":
default:
$content = $model->getAlbums();
require_once "biography.php";
break;
}
}
} else {
echo "Not found";
}
Heed! This is just a basic example. You should not use in production, only for studies and to be optimized/adapted to your code.
Valdeir, where can I contact you?
– Erick Pereira
Your visual explanation of regex is what was missing on +1
– Guilherme Nascimento