I am new here and have a question about URLs in WordPress. The very front-facing portion of my website uses WordPress just so I can use the CMSs and blog for my SEO. I have a real estate portion of the site written in basic PHP and I would like to see if there is a way to rewrite URLs so I can have a customer visit:
http://mysite.com/RepfirstnameReplastname
instead of
http://mysite.com/?rep=RepfirstnameReplastname
When a person now visits:
http://mysite.com/?rep=RepfirstnameReplastname
I have a header across the top float down and show the reps details. What I would like to do is just have a person go to a URL like this one instead:
http://mysite.com/RepfirstnameReplastname
I have put this code in my WordPress theme header file (header.php
) and my homepage has id[10]
if(is_page(10)){
$url = $_SERVER['REQUEST_URI'];
$repurl2 = parse_url($url, PHP_URL_PATH);
$repurl = $_GET['rep'];
$config = array(
'host' => 'xxx',
'username' => 'xxxx',
'password' => 'xxxxx',
'dbname' => 'xxxxxx'
);
$db = new PDO('sqlsrv:Server=' . $config['host'] . ';Database=' . $config['dbname'], $config['username'], $config['password']);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$getInfo = $db->prepare("SELECT * FROM representatives WHERE Website = ?");
$getInfo->bindValue(1, $repurl);
$getInfo->execute();
$rep = $getInfo->fetch(PDO::FETCH_ASSOC);
if(isset($rep['DisplayName'])){
$_SESSION['repage'] = $_GET['rep'];
$_SESSION['repphoto'] = $rep['PhotographURL'];
$_SESSION['repname'] = $rep['DisplayName'];
$_SESSION['reptext'] = $rep['WelcomeText'];
}
}
if(isset($_SESSION['repage'])){
?>
<div class="rep">
<div class="container repinfo">
<div class="row">
<div class="span1"><img src="<?=$_SESSION['repphoto'];?>"></div>
<div class="span11"><strong><? echo $_SESSION['repname']; ?></strong><br /><? echo $_SESSION['reptext']; ?>
</div>
<!--<div class="span2">
<table>
<tr><td>Name:</td><td>John Doe</td></tr>
<tr><td>Phone:</td><td>555-555-5555</td></tr>
<tr><td>Email:</td><td>John@Doe.com</td></tr>
</table>
</div>-->
</div><!-- row -->
</div><!-- rep info -->
</div><!-- rep -->
<?
}
?>
The above grabs the info I need from an old SQL server for the rep and displays their info properly. I would just like to know how to remove ?rep=
out of the URL.
/rep/RepfirstnameReplastname/
instead via a rewrite endpoint. – Milo Sep 14 '13 at 23:57