I have a folder called crm in htdocs which contains a fresh laravel 5.1
project and i am trying to acess it via http://localhost/crm/
but it just brings the index of page containing the directory contents
instead of the page mapped in my routes.php as
Route::get('/', function () {
return view('panel');
});
i have checked that apache mod_rewrite is enable in httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
then the .htaccess file in crm/public folder contains
<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>
I have also tried to change it to
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
without success.
You need to point Laravel to public directory to make it work. For example, if you've installed Laravel in C:/xampp/htdocs/ directory, you need to use these settings:
DocumentRoot "C:/xampp/htdocs/public"
<Directory "C:/xampp/htdocs/public">
Do not edit .htacces inside public folder. Try to change settings and load Laravel website by going to localhost first.
When you've edited Apache config file, you should restart web server.
Related
I want apache to rewrite everything to my index.php, meaning that apache should not process anything, it should ignore the url input and just forward it to the index.php.
I've searched for this many times, and the best solution I found was:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
But today I noticed that if I enter an existing path, apache will show the forbidden page and I don't want that. What I want is to always show the index.php whatever the uri is (obviously the part behind the domain name :P).
I'm using $_SERVER['REQUEST_URI'] to let PHP route everything, using a MVC app, so apache trying to process the url input is very conflicting.
I disabled the indexing, and I'm also thinking on denying access to the document root and allowing only the folder where the index.php is:
httpd.conf:
<Directory "/srv/http">
Options -Indexes +FollowSymLinks
AllowOverride None
Require all denied
</Directory>
vhost.conf:
<VirtualHost *:80>
ServerName example.com
#Redirect permanent / http://www.example.com/
DocumentRoot "/srv/http/example.com/www"
<Directory "/srv/http/example.com/www">
Require all granted
<Files "index.php">
SetHandler "proxy:unix:/run/php-fpm/www.example.sock|fcgi://localhost/"
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
</Directory>
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
</VirtualHost>
I even want to only allow access to the index.php file, but maybe this is overkill?
Moving Require all granted inside the <Files> block does not work, but this is secondary and you'd probably discourage me from trying (probably is not even possible, or necessary).
So, how can I prevent apache from processing the urls? To let my MVC app take care of the routing.
Well the rewrite code you are using specifically excludes existing URLs, so just stop that. You don't need the RewriteBase either.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule . index.php [L]
</IfModule>
If you need more, let me know, but looks like that should put you on the right track for what you're trying to achieve. Don't you have any image files, CSS and such you want Apache to serve itself? That's the usual reason for excluding existing URLs.
MAMP is installed in a MacBook. I use the MAMP apache.
Based on many online resources, I have done the following:
I added 127.0.0.1 my-site.local to file /etc/host.
I uncommented Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf in /Applications/MAMP/conf/apache/httpd.conf.
In /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf, I added
<VirtualHost *:80>
DocumentRoot "/Users/myname/laravel/mysite/public"
ServerName my-site.local
ServerAlias my-site.local
<Directory "/Users/myname/laravel/mysite/public">
DirectoryIndex index.php
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
In /Users/myname/laravel/mysite/.htaccess file:
<IfModule mod_rewrite.c>
Options +Indexes +FollowSymLinks +MultiViews
RewriteEngine On
#RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Require all granted
</IfModule>
After all, localhost, localhost/MAMP, localhost/phpMyAdmin, all work, EXCEPT for my-site.local.
It shows 500 Internal server error. The server encountered an internal error or misconfiguration and was unable to complete your request.
Problem Solved!
Because the apache has been updated to apache2.2,
in the Applications/MAMP/conf/apache/extra/httpd-vhosts.conf,
change Require all granted to Satisfy Any.
That is it!
It took me two days to figure it out~
I want to use mod_rewrite with Wampserver to remove "/index.php/" from addressbar. This code is suggested with Codeigniter Framework:
RewriteEngine on
#RewriteBase /
RewriteCond $1 !^(index\.php|img|table-images|robots\.txt|css|fonts|js|uploads|dbg-wizard\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
This should change this url:
mysite.local/contact_us
to this:
mysite.local/index.php/contact_us
This works with XAMPP but with Wampserver first URL generates Error 404!
I enabled mod_rewrite with Apache and there is no errors in error log.
Update:
I added .blabla in .htacess but nothing happened! It means that Apache does not read .htaccess! Why?
I added AllowOverride All to httpd-vhosts.conf.
Apache did not execute .htaccess and enabling AllowOverride in httpd.conf is not enough.
This is my httpd-vhosts.conf file:
<Directory E:\mysite\www>
Options Indexes FollowSymLinks Includes ExecCGI
#Order Deny,Allow
#Allow from all
AllowOverride All
Require all granted
</Directory>
To check that mode rewrite is working or not try these steps:
Make a folder in your root directory called htaccess_test
Create a .htaccess file, and put these code into this and save it.
options +FollowSymLinks RewriteEngine On
RewriteBase /htaccess_test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ user.php?u=$1
Create one more file called user.php and put these code into
this and save it.
<?php
if(isset($_GET['u'])){
echo $_GET['u'];
}
Now go to browser type http://localhost/htaccess_test/put_some_value_here.
If that is working than the problem is not in your apache setting.
Make sure you are editing the right .htaccess file. The .htaccess file you need to edit is in your projects' root folder, not in application or any other folder. And put these code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /root_directory_of_your_project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
My setup is OS X Yosemite, default Apache and PHP 5.6.
Vhost is set correctly, I have two other apps running ok:
<VirtualHost *:80>
ServerAdmin polar
ServerName lara5.com
ServerAlias lara5.com
DocumentRoot "/Users/polar/Sites/lara5/public"
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>
Hosts file is OK.
I've set the permissions to 777 to the whole project folder, still nothing.
If I remove .htaccess, the splash screen shows for the url lara5.com but the /home route returns 404.
I have tried both .htaccess (inside /public, ofc) Laravel provides, none of them work, 500 doesn't matter which route I access.
Default:
<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>
Other one from the docs:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Any ideas?
Thanks.
Translating comment into an answer to help out anyone else comes across this problem.
Based on your snippet from error.log it seems that Options directive isn't allowed in your .htaccess.
You can fix this error by commenting any line in your .htaccess starting from:
Options
To enable use of Options in .htaccess use:
Options All
in your Apace config's <Directory> section of your DocumentRoot.
I've created a WebApp on Mac OS X 10.9. If I just go to something like the index.html it works fine, so I know the apache config there is working. Now I'm trying to get a rewrite rule to work for Restler and am having issues. My httpd.conf file looks like this:
Alias "/dts" "/Library/Server/Web/Data/WebApps/dts"
<Directory "/Library/Server/Web/Data/WebApps/dts">
AllowOverride All
Options Indexes -MultiViews FollowSymLinks
</Directory>
Now I want a path like https://myserver.com/dts/api/foo to redirect to the index.php file in the api directory, so I put a .htaccess file in the api subdirectory:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Library/Server/Web/Data/WebApps/dts/api
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
php_flag display_errors On
</IfModule>
The last line of my rewrite log has the correct path showing:
(1) pass through /Library/Server/Web/Data/WebApps/dts/api/index.php
But what the browser returns is:
The requested URL /Library/Server/Web/Data/WebApps/dts/api/index.php was not found on this server.
If I do an ls -l of that path it's absolutely there. What am I doing wrong?