1

http://localhost/customers/website/jobs/28

When for an example the URL above is visited and my code is used, it goes to: http://localhost/customers/website/jobs/startpage

if(isset($_COOKIE["startpage"])) {

    }else{
        header("Location: startpage");
    }

But if I do header("Location: /startpage"); it becomes http://localhost/startpage

My Htacess is:

RewriteEngine On
RewriteBase /customers/website/

RewriteRule ^startpage/?$    startpage.php    [NC,L]

How can I make it go to http://localhost/customers/website/startpage?

2
  • What does your directory structure look like? Where is the .htaccess file located? Commented Feb 15, 2016 at 6:14
  • it's located at /customers/website/ Commented Feb 15, 2016 at 6:19

1 Answer 1

1

Don't use PHP for this. You can do this in htaccess itself:

RewriteEngine On
RewriteBase /customers/website/

RewriteCond %{HTTP_COOKIE} !startpage
RewriteRule !^startpage/?$ startpage [L,NC,CO=startpage:1:%{HTTP_HOST},R=302]

RewriteCond %{HTTP_COOKIE} startpage
RewriteRule ^startpage/?$ startpage.php [L]

and remove your header function call from PHP code.


If you will want to do this in PHP itself then use:

if(isset($_COOKIE["startpage"])) {
   //
} else {
   header("Location: " . $_SERVER["BASE"] . "startpage");
}

and keep same rewrite rule shown in question.

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.