0

I have a document called content.php, who server the content list published from two different categories.

So in both cases, catgory_1 list and _category_2 list is server by content.php

mysite.com/category_1/post/

mysite.com/category_2/post/

So, I need to redirect the user to a different page depending on catgory_? list, but without affecting the post inside that category.

Resume :

if you visit mysite.com/category_1/post/ or mysite.com/category_2/post/ ( you get the post)

But :

if you visit mysite.com/category_1/ (you get redirected to page 1) if you visit mysite.com/category_2/ (you get redirected to page 2)

1 Answer 1

1

You can do something like this. First get your url path with $_SERVER["REQUEST_URI"]. Then get all after category_, and if all after category is number then redirect.

$uri = $_SERVER["REQUEST_URI"];
$getCategory = substr($uri, strpos($uri, "category_")+9);
$getCategory = str_replace("/", "", $getCategory);

if (is_numeric($getCategory)) {
    header('Location: http://www.example.com/1');
}
else{
    header('Location: http://www.example.com/2');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.