【发布时间】:2016-08-14 09:55:45
【问题描述】:
所以,我开发了一个功能齐全的 Laravel 5 应用程序并将其部署到我客户的服务器上,运行 Apache2、PHP5 和 MySQL。该应用程序按预期工作,并且 URL 已正确重写。
我现在需要简单地将我的应用程序克隆到另一台服务器,该服务器运行完全相同的堆栈。问题是我需要将我的应用程序放在一个子文件夹中,以便可以通过匹配模式 domain2.com/movedApp 的 URL 访问它。
换句话说: 第一个服务器响应:
domain1.com/my/routes
第二台服务器需要响应:
domain2/movedApp/my/routes
我试图准确复制在第一台服务器上工作的 VirtualHost 指令,在需要的地方添加 /movedApp 并将 RewriteBase 添加到新的 .htaccess 文件夹中的 .htaccess 文件中,但无济于事。
我注意到从以下 URL 正确地遵循了路由:
domain2.com/movedApp/public/index.php/my/routes
我仍然在 Apache2 日志中的资产上收到 404 错误。
我特此报告我的 .htaccess 文件位于我的工作 Laravel 应用程序的 public 文件夹中。
.htaccess
<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>
我还报告了 Web 服务器用于为我的应用程序提供服务的配置文件
default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/galmaster/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/galmaster/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
【问题讨论】:
-
你成功了吗?
-
是的,我确实有。有空的时候我会尽快发布详细信息。我只用了两个
.htaccess文件就解决了这个问题。 -
我发布了我自己问题的答案供您查看。也许我的解决方案也适合你。
标签: php apache .htaccess laravel