[英]Laravel pretty URLs and routing not working on LAMP
我使用Laravel创建了Web应用程序,并在laravel服务器( php artisan serve
)上对其进行了测试,现在我想将其放在LAMP上,以便我可以对其进行进一步测试,但是出了点问题。
当我访问localhost/public/
,会得到我的主页,但是当我单击应用程序内的任何链接时,会出现Not found
错误。 另一方面,当我手动输入localhost/public/index.php/someURL
我得到了链接页面。
有人可以告诉我如何解决此问题吗?
这是我在public
目录中的.htaccess
文件:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
这是apache2 conf文件( /etc/apache2/sites-available/000-default.conf
)的内容:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/
<Directory "/var/www/html">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我使用以下命令启用了mod_rewrite: sudo a2enmod rewrite
我正在使用Ubuntu 14.04。
更新:
应用程式放置在/var/www/html/
转到/etc/apache2/apache2.conf文件,并确保它看起来像这样:
<Directory /var/www/html>
Options Indexes FollowSymLinks
Allowoverride All
Require All Granted
</Directory>
您可以在之后找到它
<Directory /usr/share>
....
</Directory>
执行mod_rewrite并重新启动apache,它应该可以工作!
这就是我解决的方法。 我创建了另一个.htaccess文件,并将其放在根目录/ www / html /中:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
从此处获取的信息: http : //driesvints.com/blog/laravel-4-on-a-shared-host
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.