Rewriting URLs with include does not load stylesheet

All my files are in the public_html folder. I rewrote the URL of the pages using .htaccess, for example, the URL mywebsite.com/balance.php looks like mywebsite.com/myaccount/balance .

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

Both .php and .css files are in the public_html folder.

If I rewrite the URL on mywebsite.com/balance , it works.

How can I make this work with this β€œvirtual” folder in the URL?

0
source share
3 answers

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

 /css/styles.css 

or whatever.

+3
source

The style sheet address may be incorrect. You must use absolute paths.

If your structure looks like this:

 /balance.php /style.css 

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

And rewrite it to: /myaccount/balance

The browser will look for the style.css file in /myaccount/balance/style.css .

Just change it to an absolute path and everything will be all right.

+1
source

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

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

All Articles