Make domain folder act as root

Ahmed

New Member
#1
I have a domain for example https://test.com this domain contain a full project in https://test.com/system.
Whenever I write <link ref="stylesheets" href="/style/main.css"> it search in the domain root not in the system directory which the project in.
What I have tried to do:
I have tried to edit all my path to be equal to href="style/main.css" instead of href="/style/main.css".

This solution works but I won't do this every time I go in production mode.
What I am trying to do:
I know there is a solution using .htaccess but I don't know how to write it..
 

Admin

Administrator
Thành viên BQT
#2
Try
Mã:
<link ref="stylesheets" href="./system/style/main.css">
or
Mã:
<link ref="stylesheets" href="../system/style/main.css">.
If it still won't work, use three dots.
Mã:
<link ref="stylesheets" href=".../system/style/main.css">.
It has worked for me.

To set a subdirectory as root with .htaccess
It will depend, with some hosting services you only need to add this line:

Mã:
RewriteBase   /system
If that doesn't works for you, try this:
Mã:
RewriteEngine On
# Map http://www.example.com to /system.
RewriteRule ^$ /system/ [L]
# Map http://www.example.com/x to /system/x unless there is a x in the web root.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/system/
RewriteRule ^(.*)$ /system/$1
# Add trailing slash to directories within system
# This does not expose the internal URL.
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^system/(.*[^/])$ http://www.example.com/$1/ [R=301]
 

Từ khóa phổ biến

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top