Created
April 26, 2018 08:34
-
-
Save relliv/8bdf01a96790fecbc380c4fc52316551 to your computer and use it in GitHub Desktop.
SEO Sef Link Basic Example
This file contains 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
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
# POSTS URL | |
RewriteRule ^([0-9-]+)/([0-9-A-z-]+)/([0-9-A-z-]+)(.*)$ post.php?date=$1&category=$2&sef_link=$3 | |
</IfModule> |
This file contains 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 | |
require_once(__DIR__.'/connection.php'); | |
$conn = new Connection(); | |
$db = $conn->MySQLConnection(); | |
require_once(__DIR__.'/common.php'); | |
$common = new Common(); | |
if ($common->post('title')){ | |
$date = date('Y-m-d'); | |
$title = $common->post('title'); | |
$seflink = $common->sefLink($title); | |
$category = $common->sefLink($common->post('category')); | |
$content = $common->post('content'); | |
// insert post | |
$query = $db->prepare("INSERT INTO posts SET date=:date, title=:title, category=:category, content=:content, sef_link=:sef_link"); | |
$query->execute(array( | |
"date" => $date, | |
"title" => $title, | |
"category" => $category, | |
"content" => $content, | |
"sef_link" => $seflink | |
)); | |
// if inserting success | |
if ($query){ | |
$dir = dirname($_SERVER['REQUEST_URI']); | |
echo "Your new URL <a href=\"http://{$_SERVER['SERVER_NAME']}{$dir}/{$date}/{$category}/{$seflink}.html\" target=\"_blank\">\"{$title}\"</a>"; | |
} else { | |
exit("Could not inserted. Retry."); | |
} | |
} else { | |
echo "There is no posted form."; | |
} | |
unset($_POST); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<h2>Self Link Test</h2> | |
<p>A nice way to test sef link</p> | |
<!--Self Post--> | |
<form action="" method="POST"> | |
Title:<br> | |
<input type="text" name="title" value="Enter Post Title"> | |
<br> | |
Category:<br> | |
<input type="text" name="category" value="Enter Post Category"> | |
<br> | |
Content:<br> | |
<textarea type="text" name="content">Enter Content</textarea> | |
<br><br> | |
<input type="submit" value="Submit"> | |
</form> | |
</body> | |
</html> |
This file contains 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 | |
require_once(__DIR__.'/connection.php'); | |
$conn = new Connection(); | |
$db = $conn->MySQLConnection(); | |
require_once(__DIR__.'/common.php'); | |
$common = new Common(); | |
if ($common->get('date')){ | |
$date = $common->get('date'); | |
$category = $common->get('category'); | |
$seflink = $common->get('sef_link'); | |
print_r($_GET); | |
// insert post | |
$query = $db->prepare("SELECT * FROM posts WHERE date=:date AND category=:category AND sef_link=:sef_link"); | |
$query->execute(array( | |
"date" => $date, | |
"category" => $category, | |
"sef_link" => $seflink | |
)); | |
// fetch result | |
$result = $query->fetch(\PDO::FETCH_ASSOC); | |
if ($result){ | |
$title = $result["title"]; | |
$category = $result["category"]; | |
$content = $result["content"]; | |
} else { | |
exit("Not found this content. 404..."); | |
} | |
} else { | |
echo "There is no posted form."; | |
} | |
unset($_POST); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title><?= $title ?></title> | |
</head> | |
<body> | |
<h1><?= $title ?></h1> | |
<h2><?= $category ?></h2> | |
<p><?= $content ?></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment