.htaccess not working with Laravel - php

I'm using Laravel 5.1 with a PuPHPet VM using Apache (so not Homestead).
I've got the default .htaccess in my public dir;
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I've been in to the apache2.conf;
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all granted
</FilesMatch>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And I've restarted apache2;
sudo service apache2 restart
But I still get a not found on;
http://192.168.56.131/auth/register
But not on;
http://192.168.56.131/public/auth/register
So I'm not sure what to try now. Part of it must work because the index.php is no longer required
* UPDATE *
This is working;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
But this does not;
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
It just doesn't like the whole "public" thing.
This is an updated partial of my apache2.conf file;
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
So frustrating! I don't understand what I am missing here.

Your Apache config should go within the vhost config file, not htaccess.
PuPHPet uses php-fpm, mod_php support was dropped several months ago.

Try
RewriteEngine On
RewriteRule ^(.*)$ /public/$1 [L]

Related

Laravel Routes not working 404 not found

I change my pc and install lamp on Windows 10 WSL.The main index works / but the routes is not. Here is my virtual host file.
<VirtualHost 127.0.0.2:80>
DocumentRoot /var/www/devroot/lara/panel/public
DirectoryIndex index.php
<Directory "/var/www/devroot/lara/panel/public">
Options All
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
And Here is the htaccess from project
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The Error when i access a route link.
Not Found
The requested URL /lara/panel/public/admin was not found on this server.
Apache/2.4.18 (Ubuntu) Server at localhost Port 80
The Problem was the htaccess was hidden my bad i modified it to .htaccess from _htaccess and now it's working.
Your VHost Settings are incorrect. Laravel default serves to localhost:8000. You see it as output after using php artisan serve. Try this:
<VirtualHost *:80>
DocumentRoot /var/www/devroot/lara/panel/public
DirectoryIndex index.php
<Directory "/var/www/devroot/lara/panel/public">
Options All
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>

NotFoundHttpException when using alias on wamp

I create BlogTest laravel 5.6 project on local machine. I have installed wamp, and create alias like http://localhost/blogtest/. Also crete .htaccess file in root of project and in public folder.
When I try to open any route even http://localhost/blogtest/ I get NotFoundHttpException error! But if I try http://localhost/blogtest/public/ then it works!
What is problem here?
This is alias config files and .htaccess files.
blogtest.config:
Alias /blogtest "e:/test.web/Blog.Test/"
<Directory "e:/test.web/Blog.Test/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
<ifDefine APACHE24>
Require local
</ifDefine>
<ifDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from localhost ::1 127.0.0.1
</ifDefine>
</Directory>
Root .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blogtest/
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Public folder .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /blogtest/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Did anyone have similar problem?

LAMP shows index.php in var/www/html instead of project

i have installed LAMP on Ubuntu-16.04.
Now in my var/www/html I have created a file called index.php which shows info about my PHP.
Also i have a folder called FMS which is my Codeigniter Project Folder.
When I fire localhost/FMS it shows the url to be : localhost/FMS/secure/login
but displays the index.php page
is this issue of codeigniter/.htaccess ??
Or is there anything wrong with my server configuration ?
.htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /FMS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<ifModule mod_headers.c>
Header add Access-Control-Allow-Origin "*"
</ifModule>
<IfModule !mod_rewrite.c>
apache2.conf
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Framework URL rewriting

When I load http://localhost/test, I get redirected to http://localhost/public/?_url=/test
Here is my Apache config. I also tested to make sure rewrite_module is loaded.
DocumentRoot "/var/www/myapp/"
<Directory "/var/www/myapp/">
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I created the project using Phalcon Dev Tools phalcon project myapp. Here are the two .htaccess files it created automatically.
cat /var/www/myapp/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
cat /var/www/myapp/public/.htaccess
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
Using Phalcon 1.2.6, Apache/2.2.24
Firstly your apache config should be something like
DocumentRoot "/var/www/myapp/public/"
<Directory "/var/www/myapp/public/">
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Secondly there should be a .htaccess file in your public directory like this one :-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
I hope this resolves this issue.

Apache2 setting up mod_rewrite and restricting access without .htaccess file

I am following this tutorial:
http://www.phpro.org/tutorials/Model-View-Controller-MVC.html
The tutorial states you should use an htaccess file. However, the Apache2 documentation advises you to enter your .htaccess rules into the standard configuration files for better performance.
I'm working in /etc/apache2/sites-available/default.
This is what I have so far:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Deny,Allow
Deny from all
</Directory>
<Directory /var/www/>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
</Directory>
<Location /index.php>
Order Allow,Deny
Allow from All
</Location>
With these rules, index.php is accessible, but index.php?rt=blog still works, and index/blog or /blog do not. What am I doing wrong?
but index.php?rt=blog still works
You don't have any rules that make it so that doesn't work
and index/blog or /blog do not
You don't have any rules that make URLs that look like that work, though "/blog" should be rewriting to /index.php?rt=/blog.
Try something like:
<Directory /var/www/>
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+index\.php?rt=([^&\ ]+)
RewriteRule ^ /%1? [L,R]
RewriteRule ^/index/(.*)$ /$1 [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /index.php?rt=$1 [L,QSA]
</Directory>

Categories