[英]How to set root directory in php
I am developing a website based on MVC Design Pattern. 我正在开发基于MVC设计模式的网站。
I need to access to another folder from public
folder but the problem is it recognizes public folder as root directory. 我需要从接入到另一个文件夹
public
文件夹,但问题是它承认公众的文件夹的根目录。 I checked path using window.location.pathname
in javascript and it returns /
so it's literally impossible to access to out of root directory. 我在javascript中使用
window.location.pathname
检查了路径,它返回/
因此实际上无法访问根目录。
I guess .htaccess
file redirects the path. 我猜
.htaccess
文件重定向路径。 can anyone let me know how to set Web
folder as root directory ? 谁能让我知道如何将
Web
文件夹设置为根目录?
.htaccess in Web Web中的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
.htaccess in public .htaccess在公共场合
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
You are not able to access files outside of your webroot with JS. 您无法使用JS访问Webroot之外的文件。 However, you could create a Symlink in your public folder.
但是,您可以在公用文件夹中创建符号链接。
ln -s web/your/file web/public/symlink
Write this code to set root dir. 编写此代码以设置根目录。 in your index file.
在索引文件中。 It may help you to web as root.
它可能会帮助您以root用户身份进入网络。
if(!defined('ROOT_PATH')) define('ROOT_PATH','./'); //root path. Damn directories
define('ROOT_DIR',str_replace('\\\\', '/', realpath(dirname(__FILE__))).'/'); #Get real path for root dir ---linux and windows
print_r(ROOT_DIR);
set this path to your index file. 将此路径设置为索引文件。
$path = " http://www.yourdomain.com/ "; $ path =“ http://www.yourdomain.com/ ”;
define ( 'PATH', $path ); 定义('PATH',$ path);
and every where you can call "PATH" variable in php you can do vardump(PATH); 每个可以在php中调用“ PATH”变量的地方都可以执行vardump(PATH);
i hope this is helpfull.. for u 我希望这对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.