Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess make folder act as root?

Is there a way to make .htaccess tell a folder to act as the lowest level? What I mean is this, say you have a folder like so:

/about/
/contact/
/css/
/images/
.htaccess
index.php
header.php

If they are at /contact/index.php, then if I have <a href="../index.php">Home</a> to go to the home page, it works all fine, but if they are on the actual main page, it will try to go a directory lower.

The reason is because Im trying to test sites in sub-folders.

like image 895
JREAM Avatar asked Apr 09 '26 13:04

JREAM


1 Answers

The directly answer your question, the answer is no. By the time, .htaccess is read, the path was already translated to a directory.

If you want to change the root, you have to do it in httpd.conf (or rewrite all the requests in the root to the destination directory). If you want to have several roots (under different domains), you have to use virtual hosts (again, only in httpd.conf).

You can also make your site work when it's not in the root directory.

  • Use relative paths correctly ("../index.php" in "/contact/index.php" and "index.php" in the root webpages). Not a great option.
  • Use absolute paths, but prefix them with the path of the website relative to the server root. The most fool-proof way to do this setting a constant for this in a file that you include in all your scripts.
like image 72
Artefacto Avatar answered Apr 11 '26 03:04

Artefacto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!