Created
January 22, 2012 20:54
-
-
Save kopiro/1658746 to your computer and use it in GitHub Desktop.
Get the link from HTACCESS in SEO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* THE .HTACCESS FILE SYNTAX | |
.... | |
..... | |
# BEGIN FOOTER | |
Redirect 301 /github http://github.com/kopiro | |
Redirect 301 /facebook http://facebook.com/destefano.flavio | |
Redirect 301 /twitter http://twitter.com/destefanoflavio | |
Redirect 301 /flickr http://flickr.com/photos/destefanoflavio | |
Redirect 301 /wikipedia http://it.wikipedia.org/wiki/Speciale:Contributi/destefano.flavio | |
Redirect 301 /youtube http://www.youtube.com/user/destefanoflavio | |
# END FOOTER | |
.... | |
..... | |
*/ | |
function footer_link_fromhtaccess() | |
{ | |
$return = array(); | |
$content = file_get_contents("../.htaccess"); | |
if (!$content) return; | |
foreach (explode("\n", $content) as $key => $line) | |
{ | |
if ($line=="# BEGIN FOOTER") | |
{ | |
$read = true; | |
continue; | |
} | |
if ($line=="# END FOOTER") | |
{ | |
$read = false; | |
break; | |
} | |
if ($read) | |
{ | |
preg_match_all("/Redirect 301 \/(.*) (.*)/", $line, $match); | |
$service = $match[1][0]; | |
$link = $match[2][0]; | |
$service = ucwords($service); | |
array_push($return, array("service"=>$service, "link"=>$link)); | |
} | |
else | |
{ | |
continue; | |
} | |
} | |
return $return; | |
} | |
?> | |
<nav id="elsewhere"> | |
<ul> | |
<?php foreach (footer_link_fromhtaccess() as $key => $link) : ?> | |
<li><a href="<?=$link["link"]?>" target="_blank" rel="me"><?=$link["service"]?></a></li> | |
<?php endforeach ?> | |
</ul> | |
</nav> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment