0

I'm using not_found.php file for unfound files on server , and it's in Main Directory

it's style is in 'assests/css/main.css' from same Directory ,

so I make href of linking stylesheet

href="assests/css/main.css"

it works perfect if user types 'Main/wrongFile' for example , but if user typed 'Main/ez/wrongFile' , stylesheet is included wrongly due to changing of path

I'm searching for function like

$Path = FindPath('Main/assests/css/main.css');

so it gets that path wherever file is in

then I can simply

href="<?php echo $Path; ?>"
1
  • 2
    Just use an absolute href i.e. href="/Main/assests/css/main.css" Commented Oct 7, 2019 at 3:50

1 Answer 1

2

The best way to fix it is using the code below;

<link rel="stylesheet" href="/assests/css/main.css" type="text/css"/>

adding / at beginning of assests/css/main.css simply tells browsers which root directory to look at.

Option 2) Using htaccess. Add the code below into your .htaccess file

RewriteRule ^([^/]*)/assests/css/main.css$ assests/css/main.css [R=301,L,NC]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.