I have a domain that has 1000’s of pages and some how google is locating my unfriendly urls; domain.com/?epi=293
How would i best approach the 301 redirect? I know i can assign each link in HTAccess however i’m not going to put thousands of links into it. Would I use php redirect header? how does wordpress do it?
so everytime someone or google goes to domain.com/?epi=293 should redirect to domain.com/friendly_url_here.html
Well ?epi=293 would default to the DirectoryIndex directive set in your htaccess, which defaults to index.php
So, I would just do the redirect in PHP.
So something like this in index.php (or whatever u want to set it in htaccess)
if ($_GET['epi']) {
$url = get_new_url($_GET['epi']); # query where the new URL is
if ($url) {
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '.$url);
exit;
}
}
That’s what i figured.
Your script looks like it’ll check $_GET[‘epi’] regardless. If the url was friendly domain.com/name_of_url.html
epi would return name_of_url
I was thinking of checking the full url.
If full url is http://www.domain.com/name_of_url.html then its fine
If full url is http://www.domain.com/?epi=293 then i would do the Perm Redirect.
looks like i was on the right track… i thought there would be a HTAccess secret ingredient.
This is my Fullurl script
function sselfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = sstrleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; }
$FullURL = sselfURL();