如何在Laravel中使用.htaccess [英] how to use .htaccess in laravel
本文介绍了如何在Laravel中使用.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在主机中建立了一个目录:
I made a directory in my host:
www.mysite.com/test/
,我已经在其中复制了laravel文件夹.但是当我在浏览器中调用该网址时,会显示以下内容:
and I've copied my laravel folders inside it. but when I call that url on my browser it show me this:
我认为我应该做一个.htaccess
.
推荐答案
.htaccess 文件已经存在于公用文件夹中,您需要配置的是服务器
The .htaccess file is already existed in public folder what you need to configure is your server
对于Linux在终端上执行:
for Linux on terminal execute :
cd /etc/apache2/sites-available
/etc/apache2/sites-available$ sudo vi myapp.conf
添加/修改这些行以适合您的服务器
Add/Modify these lines to suit your server
<VirtualHost *:80>
ServerName myapp.localhost.com
DocumentRoot "/home/vagrant/projects/myapp/public"
<Directory "/home/vagrant/projects/myapp/public">
AllowOverride all
</Directory>
</VirtualHost>
保存文件,然后在下面继续.
Save the file, then continue below.
/etc/apache2/sites-available$ cd ../sites-enabled
/etc/apache2/sites-enabled$ sudo ln -s ../sites-available/myapp.conf
/etc/apache2/sites-enabled$ sudo service apache2 restart
对于Laravel根文件夹中的Windows Server,添加web.config文件并在其中写入这些代码
And for Windows Servers inside your Laravel root folder add web.config file and write these codes inside it
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
</files>
</defaultDocument>
<handlers accessPolicy="Read, Execute, Script" />
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="/public/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="public/index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
)
这篇关于如何在Laravel中使用.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文