erdomester
erdomester

Reputation: 11829

URL rewrite with include does not load stylesheet

All my files are in the public_html folder. I rewrote the url of the pages with .htaccess, so e.g the url of mywebsite.com/balance.php looks mywebsite.com/myaccount/balance.

I can include a file with: <?php include 'header_login.php'; ?>, but it appears without the stylesheet.

Both this .php file and the .css file are in the public_html folder.

If I rewrite the url to mywebsite.com/balance it works.

How can I make this work with this "virtual" folder in the url?

Upvotes: 0

Views: 1373

Answers (3)

Marvin Rabe
Marvin Rabe

Reputation: 4251

The address of the stylesheet is possibly not correct. You have to use absolute paths.

If your structure is like this:

/balance.php
/style.css

In your balance.php you use: <link rel="stylesheet" href="style.css">

And rewrite it to: /myaccount/balance

The browser will look for a style.css file at /myaccount/balance/style.css .

Just change it to an absolute path and you will be fine.

Upvotes: 1

Aleksandar
Aleksandar

Reputation: 654

You can define your base url define ("BASE_URL","http://www.mysite.com"); and add BASE_URL with stylesheet like

<link rel="stylesheet" type="text/css" href="<?php echo BASE_URL; ?>/style.css">

Upvotes: 0

Your Common Sense
Your Common Sense

Reputation: 157877

Simple.
Always use absolute paths in you HTML and CSS files.
An absolute path always starting from / pointing to the web-server root.
So, make your css path like

/css/styles.css

or whatever.

Upvotes: 3

Related Questions