0

Due to some unforeseen reason, I cannot use a *.php extension for my page. And I need to put conditional redirection in the page.

I plan to use *.html, and javascript/Ajax to call a PHP which evaluates the condition and accordingly sends back a redirection command.

The condition is being evaluated, but how can I give a redirection command from this internal PHP is not clear to me.

0

3 Answers 3

2

You can actually map all your .html files to .php using .htaccess.

If that doesn't work for you, your logic should be as follows:

PHP:

echo json_encode(array("redirect_url" => $url));

Javascript with jQuery (assuming you require AJAX to redirect):

$.getJSON("PHP/Controller/Url", function(data) {
    window.location.href = data.redirect_url;
});

Javascript (if you simply serve a static html file)

<script>
window.location.href = "redirect_url";
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

You can use

window.location = "http://new-url"

or

window.location.href = "http://new-url"

Comments

0

In JS,

location.assign("http://www.google.com")

will redirect your current frame to Google.

So don't send redirect header in PHP, send "flags" in response body and use JS to redirect.

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.