Reputation: 409
When I open http://my-domain.com/register it works fine but when I try to open http://my-domain.com/register/ then it misses CSS and other things
I have two pages in my public_html folder, a CSS directory and .htaccess -
public_html
.index.html
<?php
$path = $_SERVER['REQUEST_URI'];
$chunks = explode("/", $path);
print_r($chunks);
if($chunks[1] == "register") {
require_once("register.php");
}
?>
.htaccess
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</ifModule>
Upvotes: 0
Views: 1175
Reputation: 143876
You need to add a:
<base href="/" />
to your page header.
Or change your links to absolute URLs.
The "/" at the end means the browser is using /register/
is the relative URL base instead of /
when the URL is /register
.
EDIT:
is there any .htaccess way to solve this problem.
There is but it's really inefficient and if you were to ever place css or images in other places, the rule may not always fix them (or may even break them):
RewriteCond %{REQUEST_URI} !^/CSS/
RewriteRule ([^/]+\.css)$ /CSS/$1 [L]
RewriteCond %{REQUEST_URI} !^/Images/
RewriteRule ([^/]+\.(png|jpe?g|gif))$ /Images/$1 [L]
Upvotes: 2
Reputation: 784998
Here is a way you can fix css/js/images links using rewrite rules:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# fix css/images/js links
RewriteRule ^.+?/((?:css|images|js)/.+)$ $1 [L,NC,NE,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</ifModule>
Upvotes: 1