Jump to content

Help With Redirects


bluewaves

Recommended Posts

How do I set up a redirect?  I have some pages on my site that have two pages with essentially the same stuff on it.

I really should do a redirect on one of them. If people have bookmarked that url, will the redirect to the other page work without any harm?

 

I also have some html pages that I'd like to redirect to .php extensions.  I don't want to suffer any Google penalties for it though.

 

Does anyone feel confident in directing me?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/207379-help-with-redirects/
Share on other sites

Use this function for redirects. You can call it via.. redirect("location.php"); This means you can use it anywhere. As it also uses a header if it hasn't been sent, else a js version/meta version.

 

function redirect($location) {
    if(!headers_sent()) :
        header('Location: ' . $location);
    else :
        echo '<script type="text/javascript">window.location.href="' . $location . '";</script>';
        echo '<noscript><meta http-equiv="refresh" content="0;url=' . $location . '" /></noscript>';
    endif;
}

 

Though for redirecting .html pages to .php, this would work for ALL .html pages in .HTACCESS

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [NC]

 

Even for your first question, this can be used

Redirect 301 /oldpage.php http://www.example.com/newpage.php

Link to comment
https://forums.phpfreaks.com/topic/207379-help-with-redirects/#findComment-1084957
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.