Reputation: 53
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
Upvotes: 0
Views: 88
Reputation: 37
Prateek's answer is good, but I solve similar problem by adding.
<base href="/"/>
in my head tag.
or you can experiment with different folder like:
<base href="/web/"/>
and etc.
Upvotes: 0
Reputation: 854
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">
Upvotes: 1