久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

帶有 .htaccess 的 PHP 根目錄

PHP root with .htaccess(帶有 .htaccess 的 PHP 根目錄)
本文介紹了帶有 .htaccess 的 PHP 根目錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用的是 000webhost,它使用根文件夾中的 public_html 文件夾作為站點的可見根.在那個文件夾中,我有一個包含一些 PHP 腳本的資產(chǎn)文件夾,以及包含 PHP 索引頁面的其他文件夾.使用 require "/assets/includes/scriptname.php"; 不起作用,因為它試圖找到 public_html 的同級文件夾.我可以編輯 .htaccess 以更改相對于 PHP 查找的根文件夾,但我不知道如何操作.

I'm using 000webhost, which uses a public_html folder in the root folder as the visible root for the site. In that folder, I have an assets folder with some PHP scripts, and other folders with PHP index pages. Using require "/assets/includes/scriptname.php"; does not work, as it tries to find a sibling folder to public_html. I'm allowed to edit .htaccess to change the root folder relative to the PHP lookup, but I don't know how.

文件樹:

public_html (within root, but simulated root)
   folder1
      index.php
   folder2
      index.php
   folder3
      index.php
   assets
      subfolder
      subfolder
   index.php

簡而言之,如何在 /public_html/ 中創(chuàng)建提到的代碼點而不顯式聲明它(最好作為 .htaccess 更改,因為我希望我的代碼能夠移動到無需重寫任何內(nèi)容的不同主機).

In short, how do I make the mentioned code point inside /public_html/ without explicitly declaring it (preferably as a .htaccess change, as I want my code to be able to be moved to a different host without rewriting anything).

對于 .htaccess 重寫的答案,您能解釋一下它的每一行是如何工作的嗎?謝謝.

For an answer with the .htaccess rewrite, could you explain how each line of it works? Thanks.

推薦答案

.htaccess 對您沒有幫助.它是一個 Apache 配置,它不會以任何方式影響 PHP 的行為.

.htaccess does not help you. It is an Apache configuration and it does not affect the behavior of PHP in any way.

代碼:

require "/assets/includes/scriptname.php"

告訴 PHP 使用絕對路徑包含文件.不推薦使用硬編碼的絕對路徑,因為當您將其移動到另一個目錄或具有不同路徑的不同服務器時,代碼將不起作用.

tells PHP to include a file using an absolute path. Using hardcoded absolute paths is not recommended because the code won't work when you move it into another directory or on a different server that has different paths.

指定包含文件路徑的最佳方法是在運行時生成它,從包含程序的路徑開始.PHP 函數(shù) dirname() 和常量 __DIR__ 是這里的幫手.

The best way to specify the path of an included file is to generate it runtime, starting from the path of the includer. The PHP function dirname() and the constant __DIR__ are the helpers here.

給定示例文件結構:

public_html
   |
   +- index.php
   |
   +- assets
   |     |
   |     +- somescript.php
   |
   +- includes
         |
         +- header.php
         |
         +- footer.php

假設您需要在 index.php 中包含 assets/somescript.php.在 index.php 中寫入:

Let's say you need to include assets/somescript.php in index.php. Write this in index.php:

 require __DIR__.'/assets/somescript.php';

魔術常量 __DIR__ 包含使用它的文件的目錄.對于 index.php__DIR__ 設置為 '/(...path-to-your-user-directory...)/public_html'.

The magic constant __DIR__ contains the directory of the file where it is used. For index.php, __DIR__ is set to '/(...path-to-your-user-directory...)/public_html'.

如果 somescript.php 需要包含 header.php 它應該這樣做:

If somescript.php needs to include header.php it should do it like this:

require dirname(__DIR__).'/includes/header.php';

等等.

通過這種方式,您可以將整個應用程序移動到不同的目錄、不同的服務器甚至不同的操作系統(tǒng)上,它仍然可以工作.

This way you can move the entire application to a different directory, on a different server and even on a different OS and it will still work.

這篇關于帶有 .htaccess 的 PHP 根目錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網(wǎng)站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 成人午夜电影在线观看 | 国产精品久久久久久久粉嫩 | 91精品久久久久久久久久入口 | 日韩精品在线播放 | 中文字幕视频一区二区 | 91亚洲精选| 婷婷亚洲综合 | 中文字幕视频在线观看 | 麻豆国产一区二区三区四区 | 国产欧美一区二区久久性色99 | 久久久久国产一区二区 | www.99热.com | 国产视频中文字幕在线观看 | 日韩一区二区福利视频 | 成人精品视频在线观看 | 欧美午夜精品理论片a级按摩 | 欧美成人精品在线 | 久久av一区 | 久久com | 国产日韩欧美一区 | 精品视频亚洲 | 欧美日高清视频 | 亚洲 91| 精品影视| 中文字幕亚洲专区 | 亚洲精品久久久 | 亚洲最色视频 | 精品欧美一区二区精品久久久 | 久久久91 | 一区二区三区四区免费在线观看 | 视频一区在线 | 紧缚调教一区二区三区视频 | 亚洲精品1区 | 日韩免费av| 99精品国产一区二区青青牛奶 | 99久久婷婷国产综合精品电影 | 久久久久久久久久影视 | 久久久久午夜 | 免费精品 | 全部免费毛片在线播放网站 | 久久久国产网站 |