Tiago
Tiago

Reputation: 653

php rewrite rules htaccess problems with CSS and JS

I'm having some trouble when applying rewrite rules to my pages.

My scheme is the following:

Assets (contains all subfolders with JS, CSS, IMG, etc)
header.php
footer.php
index.php (that have all links to all other files -> index.php?id=page

Now, I'm having some troubles when creating a rewrite rule with second level. For example, I have the page:

edit-language -> that opens the page index.php?id=edit-language

This page lists all languages and have some options to user choose:

edit-language/delete/X -> opens the same page above but with &delete=X -> both X are the ID
edit-language/publish/X -> opens the same page above but with &publish=X -> both X are the ID

Now, The rewrite rule I have for main page:

RewriteRule ^edit-lang/?$ index.php?id=edit-lang [L]

And this works just fine, but when I create the rule for another level /something/something it lost all CSS files. For example:

RewriteRule ^edit-lang/delete/(.*)$ index.php?id=edit-lang&delete=$1 [L]

All my assets are being loaded in header and footer PHP files like src="assets/js/..."

Can someone help me please? Thanks!

Upvotes: 2

Views: 45

Answers (1)

delboy1978uk
delboy1978uk

Reputation: 12375

I'll take a guess here - you are using relative links?

src="css/some.css"

This looks from the current folder. As you are now on a different folder level, the files are not available and will 404.

Always use an absolute link starting with a slash like so:

src="/css/some.css"

This way it will start looking from your site root, and shouldn't 404 any more.

Upvotes: 1

Related Questions