Mobile app version of vmapp.org
Login or Join
Moriarity557

: Link stylesheets up directories using .htaccess How do I move up a directory using the <link> in HTML for my stylesheets to work while using htaccess? My directories are as: index.php .htaccess

@Moriarity557

Posted in: #Css #Htaccess #Html

How do I move up a directory using the <link> in HTML for my stylesheets to work while using htaccess?

My directories are as:

index.php
.htaccess
css/
styles.css
php/
login.php


In my htaccess, it contains:

RewriteRule ^login/?$ php/login.php [L,QSA,NC]


Now, the stylesheets work when I copy the css folder to inside my php. They work with href="css/styles.css".

I don't want that. I want to move up and out of the php directory to the css folder in my root directory. But the stylesheets won't show when the href="../css/styles.css".

How do I move up a directory to use my stylesheet in the root css folder with htaccess?

EDIT: I have tried using the <base href="/" />, but that prevents the stylesheets from loading on both /login/ and /login.php.

login.php:

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="../js/system.js"></script>
<link href="../css/styles.css" rel="stylesheet" />


.htaccess:

ErrorDocument 404 localhost/Sites/OrderFresh/html/error404.html RewriteEngine On
RewriteRule ^login/?$ php/userconnect.php [L,QSA,NC]
<Files .htaccess>
order allow,deny
deny from all
</Files>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Moriarity557

1 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

I get around this problem using site relative linking for CSS and JS files.

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="/js/system.js"></script>
<link href="/css/styles.css" rel="stylesheet" />


When the URL starts with a slash, that tells the browser to start at the document root for the site. Your CSS and JS files will then be correctly linked no matter what directory your page looks like it is in.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme