Htaccess CSS not working

622 views Asked by At
RewriteEngine On
RewriteBase /games4u/
RewriteRule    ^index/?$    index.php    [NC,L]

RewriteRule ^forum/([a-zA-Z0-9_-]+)$ forum.php?user=$1
RewriteRule ^forum/([a-zA-Z0-9_-]+)/$ forum.php?user=$1

So what I want is the url to be: localhost/forum/1 1 = user id 1. But the design wont load because of this. It's like the CSS file gets removed or something. Why doesn't thios work?

2

There are 2 answers

1
Ron Dadon On

You need to set conditions for your re-writing, to ignore folders and files:

RewriteEngine On
RewriteBase /games4u/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule    ^index/?$    index.php    [NC,L]
RewriteRule ^forum/([a-zA-Z0-9_-]+)$ forum.php?user=$1
RewriteRule ^forum/([a-zA-Z0-9_-]+)/$ forum.php?user=$1

Also, it's recommended that you will use the full path for your css / js files, such as:

<script src="http://www.example.com/js/file.js"></script>
0
Jon Lin On

When you add extra / slashes in the URL, that changes what the relative URL base becomes. The browser doesn't know that /games4u/ is the base for relative URL's generated by the forum.php code. Now that you've added another level of folders, /games4u/forum/username, the browser attempts to resolve relative URLs by adding the base: /games4u/forum/ to all the links. You need to specify your base in the page headers or make all your links absolute (starts with /games4u/):

<base href="/games4u/" />

The RewriteBase directive has nothing to do with the relative URL base on the browser. The browser doesn't even know you're using rewrite rules. The RewriteBase directive is only for relative paths in your RewriteRules.