[ SEO Friendly URL output Un-Styled HTML page with PHP ]
I have a problem with my URL re-writes. The link works, but output's plain un-styled HTML. Not seen this before, or i am overlooking something very simple so any help would be greatfully received.
This is my .htacess re-write
RewriteRule ^gallery/([0-9]+)/([a-zA-Z0-9_-]+) gallery.php?id=$1
This is my php function
function url_slug($string, $space = '-') {
$string = str_replace('&', 'and', $string);
$string = preg_replace('/[^a-zA-Z0-9 _-]/', '', $string);
$string = strtolower($string);
$string = preg_replace('/[ ]+/', ' ', $string);
$string = str_replace(' ', $space, $string);
return $string;
}
This is my index page with the gallery section
<?php
$sql = DB::getInstance()->query('SELECT * FROM gallery ORDER BY id ASC LIMIT 0, 6');
foreach($sql->results() as $row) {
?>
<div class="col-md-4 col-sm-6 port-item">
<div class="port-mask">
<?php
$id = escape($row->id);
$title = escape($row->url);
$string = url_slug($title);
echo '<a href="gallery/' . $id . '/' . $string . '"><h3>' . escape($row->section_title) . '</h3></a>';
?>
<div class="port-line clearfix"></div>
<p><?php echo escape($row->section_category) ?></p>
<?php
echo '<a href="gallery/' . $id . '/' . $string . '"><i class="viewbtn fa fa-long-arrow-right"></i></a>';
?>
<a href="images/gallery/<?php echo escape($row->section_image) ?>" data-rel="prettyPhoto"><i class="viewimg fa fa-search"></i></a>
</div>
<img src="images/gallery/<?php echo escape($row->section_image) ?>" alt="<?php echo escape($row->alt) ?>">
</div>
<?php
}
?>
This is my gallery.php from the link above
<?php
$sql = DB::getInstance()->get('gallery', array('id', '=', Input::get('id')));
foreach($sql->results() as $row) {
?>
<section class="top-content clearfix">
<div class="clearfix big-box para-opacity" data-auto-play="9000" data-stellar-ratio="0.4" data-stellar-position-property="position">
<div class="box-title">
<p><?php echo escape($row->gallery_slider_p) ?></p>
<div class="clearfix"></div>
<h3><?php echo escape($row->gallery_slider_h3) ?></h3>
</div>
<div class="works-slider slider" data-auto-play="9000">
<div class="slide img-bg clearfix" data-background="images/gallery/<?php echo escape($row->gallery_slider) ?>"></div>
</div>
</div>
</section>
<?php
}
?>
The URL link when clicked looks like this from index.php
http://localhost/projects/XXXPROJECTXXX/index
to the gallery.php
http://localhost/projects/XXXPROJECTXXX/gallery/1/chinese-contemporary-abstract-lady
So, what is wrong?? Thanks in advance :-)
Answer 1
.htaccess create's problem with url,
what you can change all your urls of
image
js
css
into absolute url, add your domain in them, this works for me.