I am trying to create a htaccess for seo urls, I created my htaccess all urls works fine exclude subfolder with parameters, they redirects to sitefolder.
sitefolder is my root all files are in there.
Example : Url should look like this :
http://localhost/sitefolder/subcat/39/web-hosting
http://localhost/sitefolder/profile/1/username
in htaccess its like this :
RewriteRule ^subcat/(.*)/([a-zA-Z0-9_-]+)$ subcat.php?q=$1&slug=$2 [L,NC]
RewriteRule ^profile/(.*)/([a-zA-Z0-9_-]+)$ show_profile.php?q=$1&slug=$2 [L,NC]
First parameter is id and second is slug, but both urls doesn't go to url.
Here is all my htacces codes :
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^contact-us contact-us.php [L,NC]
RewriteRule ^login login.php [L,NC]
RewriteRule ^register register.php [L,NC]
RewriteRule ^search search.php [L,NC]
RewriteRule ^about-us about-us.php [L,NC]
RewriteRule ^(.*)/([a-zA-Z0-9_-]+)$ detail.php?q=$1&slug=$2 [L,NC]
RewriteRule ^cats categories.php [L,NC]
RewriteRule ^subcat/(.*)/([a-zA-Z0-9_-]+)$ subcat.php?q=$1&slug=$2 [L,NC]
RewriteRule ^profile/(.*)/([a-zA-Z0-9_-]+)$ show_profile.php?q=$1&slug=$2 [L,NC]
And this is how I Get parameters in subcat.php, I don't redirect to index on error so I dont think its because of php :
if(!empty($_GET['slug']) AND !empty($_GET['q'])) {
$slug = $_GET['slug'];
$pid = is_numeric($_GET['q']);
$userQuery = $handler->getPosts("SELECT * FROM categories WHERE catId = ?", [$pid])->fetchAll();
if($userQuery) {
foreach($userQuery as $user){
$catid = intval($user['catId']);
$cat_title = htmlspecialchars($user['catName']);
$cat_seo_url = htmlspecialchars($user['cat_seo_url']);
$cat_descriptions = htmlspecialchars($user['cat_desc']);
$cat_keywords = htmlspecialchars($user['cat_keys']);
$cat_created = htmlspecialchars($user['cat_created_at']);
$cat_img = htmlspecialchars($user['cat_img']);
}
}else{
echo "Something went wrong while execute query.";
exit();
}
}else{
echo "Something went wrong with parameters";
exit();
}