Pag-redirect ng PHP mula sa pahina patungo sa URL.PHP 301 redirect.
Ang pag-redirect ng PHP na ito ay dapat magbalik ng HTTP response status code: 301 Moved Permanently.
Ginagamit ng mga search engine ang 301 response status code upang ilipat ang ranggo ng page mula sa lumang URL patungo sa bagong URL.
Palitan ang old-page.php code ng redirection code sa new-page.php.
old-page.php:
<?php
// PHP permanent URL redirection
header("Location: http://www.domain.com/new-page.php", true,
301);
exit();
?>
Ang lumang pahina ay dapat may .php file extension.
Maaaring may anumang extension ang bagong page.
php-redirect-test.php
<?php
// PHP permanent URL redirection test
header("Location:
https://cmtoinchesconvert.com/tl/web/dev/php-redirect.html", true, 301);
exit();
?>
Pindutin ang link na ito upang mag-redirect mula sa php-redirect-test.php pabalik sa pahinang ito:
Pagsubok sa pag-redirect ng PHP - PHP file
php-redirect-test.htm
<?php
// PHP permanent URL redirection test
header("Location:
https://cmtoinchesconvert.com/tl/web/dev/php-redirect.html", true, 301);
exit();
?>
Ang pag-redirect ng PHP mula sa html file php-redirect-test.htm ay karaniwang hindi gagana dahil sa .html file extension, maliban kung ito ay pinagana sa .htaccess o httpd.conf file:
Pagsubok sa pag-redirect ng PHP - HTML file
Upang paganahin ang PHP sa mga HTML na file, idagdag ang code na ito sa .htaccess o httpd.conf file:
Addtype application/x-httpd-php .htm .html
Advertising