在子目录htaccess的安装Laravel 5应用程序 [英] Install Laravel 5 app in subdirectory with htaccess
问题描述
的设置
我想我的服务器上安装此目录中laravel 5应用程序:
的public_html / MyApp的/
和我希望它在这个URL来访问:
http://www.example.com/myapp/
我创造了这个的.htaccess规则并把它放在了的myapp </ code>文件夹,以便将请求重定向:
RewriteEngine叙述上
重写规则^(。*)$的公共/ $ 1 [L]
问题:
在我的浏览器,当我尝试访问该应用程序我重定向的URL一样:
-
http://www.example.com/myapp/public/index.php
-
http://www.example.com/myapp/public/index.php/dashboard
,而不是像漂亮的pretty的网址:
-
http://www.example.com/myapp/
-
http://www.example.com/myapp/dashboard
什么我需要在我的.htaccess文件更改为获得工作正确的网址?
更新:laravel应用程序可以在其他地方被移动,如果需要,只要所需的URL结构上述(含有example.com/myapp/访问的应用程序)就可以实现。
更新:当我尝试访问 example.com/myapp/dashboard
我收到在浏览器中出现以下错误消息:编译 NotFoundHttpException。 PHP的行7793:
与开头堆栈跟踪:
在compiled.php行7793
在RouteCollection-&GT;匹配(对象(请求))的compiled.php行7066
在路由器 - &GT; findRoute(对象(请求))的compiled.php行7038
在路由器 - &GT; dispatchToRoute(对象(请求))的compiled.php行7030
在路由器 - &GT;讯(对象(请求))的compiled.php行1989
在内核级&GT;照亮\基金会\ HTTP \ {关闭}(对象(请求))
更新:下面的.htaccess文件位于公共文件夹:
&LT; IfModule mod_rewrite.c&GT;
&LT; IfModule mod_negotiation.c&GT;
选项-MultiViews
&LT; / IfModule&GT;
RewriteEngine叙述上
#重定向结尾的斜杠...
重写规则^(。*)/ $ / $ 1 [L,R = 301]
#拉手前端控制器...
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^的index.php [L]
&LT; / IfModule&GT;
您可以轻松地在的myapp增加额外的
文件夹(这将重定向的.htaccess
文件实现这一目标的myapp </ code>所有请求的文件夹复制到
公开
,因为它应):
&LT; IfModule mod_rewrite.c&GT;
RewriteEngine叙述上
重写规则^(。*)$的公共/ $ 1 [L]
&LT; / IfModule&GT;
您也应该修改的.htaccess
在的myapp /公共
目录,如:
&LT; IfModule mod_rewrite.c&GT;
选项-MultiViews
RewriteEngine叙述上
的RewriteBase / MyApp的/
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则。的index.php [L]
&LT; / IfModule&GT;
这里的变化是,你重写了基本路径的RewriteBase / MyApp的/
The Setup
I am trying to install a laravel 5 app in this directory on my server:
public_html/myapp/
And I want it to be accessed at this URL:
http://www.example.com/myapp/
I have created this .htaccess rule and placed it in the myapp
folder in order to redirect requests :
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
Problem:
In my browser when I try to access the app I get redirected URLs like:
http://www.example.com/myapp/public/index.php
http://www.example.com/myapp/public/index.php/dashboard
instead of nice pretty URLs like:
http://www.example.com/myapp/
http://www.example.com/myapp/dashboard
What do I need to change in my .htaccess file to get proper URLs working?
Update: The laravel app can be moved elsewhere if needed, as long as the desired URL structure above (with the app accessible at example.com/myapp/) can be achieved.
Update: When I try to access example.com/myapp/dashboard
I receive the following error message in the browser: NotFoundHttpException in compiled.php line 7793:
with a stack trace that starts with:
in compiled.php line 7793
at RouteCollection->match(object(Request)) in compiled.php line 7066
at Router->findRoute(object(Request)) in compiled.php line 7038
at Router->dispatchToRoute(object(Request)) in compiled.php line 7030
at Router->dispatch(object(Request)) in compiled.php line 1989
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
Update: The following .htaccess file is located in the public folder:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
You can easily achieve this by adding additional .htaccess
file in the myapp
folder (this will redirect all of your requests in myapp
folder to the public
as it should):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
You should also modify the .htaccess
in your myapp/public
directory, like this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /myapp/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
</IfModule>
The change here is that you rewrite the base path RewriteBase /myapp/
这篇关于在子目录htaccess的安装Laravel 5应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!