I am trying to route a single blog post from a url
The url looks like this : http://localhost/news/post/1/post-title-slug
And my .htaccess
:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [QSA,L]`
And my routing file I am currently using a library called nezamy/route
$route->get('/post/?/?', function($postid,$page) { include 'post.php'; });
When I do this my css
, js
and images
is renamed as well to something like this: http://localhost/news/post/1/css/main.css
Advertisement
Answer
You need to add the css/js files with their absolute location when using htaccess rewrites. To do this, you can define your base url in a php variable as shown below:
$base_url = 'http://localhost/';
and then refer to it where you call the css/js files like so
<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?>css/main.css">