简体   繁体   English

.htaccess目录被更改

[英]Directory of .htaccess get changed

In my laravel project. 在我的laravel项目中。 I have changed the directory for htaccess file to root directory from public folder. 我已经将htaccess文件的目录从公用文件夹更改为根目录。 Now asset() is not working properly on server to access the files. 现在asset()在服务器上无法正常访问文件。 I think changes required in htaccess file. 我认为htaccess文件中需要进行更改。

I replace asset() with URL::asset() and url() but it is not working. 我用URL :: asset()和url()替换了asset(),但是它不起作用。

Options -MultiViews 选项-MultiViews

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php

I want to use asset() to access files from public folder. 我想使用asset()访问公用文件夹中的文件。

.htaccess needs to be inside public/ not the root of the project. .htaccess必须位于public /而不是项目的根目录下。 Actually public/ is root for the web, end-users. 实际上public /是网络的最终用户。

The root of your Laravel project should not be publicly visible. Laravel项目的根目录不应公开可见。

I'm getting the impression that you have installed Laravel within a public folder on your server. 我得到的印象是,您已在服务器的公用文件夹中安装了Laravel。 Is this what you have done? 这是你做的吗?

/home/{user}/public_html/{your Laravel installation}

You would be better off moving the Laravel installation to it's own folder outside of public root. 您最好将Laravel安装移动到公共根目录之外的其自己的文件夹中。

/home/{user}/laravel/{your Laravel installation}

Then, you can remove the public_html folder and replace it with a symlink to your laravel/public folder. 然后,您可以删除public_html文件夹,并用指向您的laravel/public文件夹的符号链接替换它。

rmdir /home/{user}/public_html
ln -s /home/{user}/laravel/public /home/{user}/public_html

This will allow you to maintain the security of your application files. 这将使您能够维护应用程序文件的安全性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM