简体   繁体   中英

301 permanent redirect in PHP

I am new to PHP, This is not working when i redirect in php: <?php echo validation::safeOutputToScreen($file->getNextDownloadPageLink()); ?> <?php echo validation::safeOutputToScreen($file->getNextDownloadPageLink()); ?>

What's wrong?

In JavaScript, It works:

<script>
window.location.replace("https://www.google.com/url?sa=t&source=web&rct=j&url=<?php echo validation::safeOutputToScreen($file->getNextDownloadPageLink()); ?>");
</script>

But when i convert my javascript to php (because i want a permanent redirect and i cant do it in javascript), it doesn't work.

// Permanent 301 redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.google.com/url?sa=t&source=web&rct=j&url=<?php echo validation::safeOutputToScreen($file->getNextDownloadPageLink()); ?>);");
exit();

Thank You!

Use concatenation instead of <?php echo... inside PHP:

// Permanent 301 redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.google.com/url?sa=t&source=web&rct=j&url=" . validation::safeOutputToScreen($file->getNextDownloadPageLink()) );
exit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM