RewriteEngine On

# If the request is for "job-title-jobid", route to jobdetail_jobdiva.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-([0-9]+)$ jobdetail_jobdiva.php?title=$1&jobid=$2 [L,QSA]

# If the request is for "job-title-jobs", route to joblistings.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-jobs$ index.php?title=$1 [L,QSA]

# If the request is for "jobs-in-{location}", route to index.php with location parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^jobs-in-([^/]+)$ index.php?location=$1 [L,QSA]


# If the request is for "title-jobs-in-{location}", route to index.php with location parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-jobs-in-([^/]+)$ index.php?title=$1&location=$2 [L,QSA]

# Remove .php extension and make the page accessible without it
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/?$ $1.php [L,QSA]