All other routes aren't working except '/' on my Laravel project - php

I'm a trying to learn the framework Laravel. I installed it and I configured the virtual hosts
When I tried to access the project, it works
but when I tried another root such as /justForTest
it didn't work
I don't know why ?!
Route::get('/', function () {
return view('welcome');
});
Route::get('/justForTest', function () {
//return view('welcome');
return "Hello world !";
});
image
I tried many solutions on the net in vain.
I use kubunto 17.04 and this is what I did
-I added the Directory with AllowOverride all on my lsapp.div.conf
<VirtualHost *:80>
ServerAdmin ham.elmaslouhi#gmail.com
ServerName lsapp.dev
ServerAlias www.lsapp.dev
DocumentRoot /var/www/html/lsapp/public
<Directory "/var/www/html/lsapp/public">
AllowOverride all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
-I have enabled the rewrite mode with a2enmod rewrite
-I added the line RewriteBase /laravel/ on my htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /laravel/
# 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Thank's for helping me.

Remove or comment #RewriteBase /laravel/ in your .htacess

Related

Why new Route in Laravel v6.9.0 is not working? Vindows 10 - XAMPP v3.2.4 (64bit)

I'm first time working in Laravel.
I've installed composer.
Installed Laravel v6.9.0 in Windows 10 with XAMPP v3.2.4 (64bit), and
PHP v7.3.12.0
im cute files from public folder in root and public folder delete
My test .htaccess by
htaccess_tester had worked
The test for mod_rewrite shows it is enabled and working
httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
In my check to Apache httpd.conf with all AllowOverride None changed to AllowOverride All
and appended end file httpd.conf file:
<Directory "C:/xampp/htdocs/Laravel Project/moda.local">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Allow from All</Directory>
my .htaccess code:
<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>
My routes.php in code:
Route::get('/', function () {return view('welcome');});
Route::get('/test1', function () {return 'test1';});
Route::get('test2', function () {return 'test2';});
my VirtualHost in c:/xampp/apache/conf/extra/httpd-vhosts.conf:
<VirtualHost *:80>
ServerName moda.local
DocumentRoot "C:/xampp/htdocs/Laravel Project/moda.local"
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/Laravel Project/moda.local">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory></VirtualHost>
My URL:
-this url worked no problem show laravel first page
http://moda.local/
-this url not work error > 404 not found
http://moda.local/test1
-this url not work error > 404 not found
http://moda.local/test2

laravel only 'sometimes' forbidden error 403

I am practicing laravel and already uploaded to production, then i have some problem and it happened just 'sometimes', when i move to move route (move to move menu / path) suddenly forbidden access 403 <<<< only sometimes, but if i clear browser my route(menu/path) worked again no problem and it happened again when left lapse of time
virtualhost :
<VirtualHost *:80>
# Index file and Document Root (where the public files are located)
DirectoryIndex index.php
DocumentRoot /var/www/html/tes/app/public
<Directory /var/www/html/tes/app/public>
Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
AllowOverride All
Require all granted
</Directory>
# Custom log file locations
#LogLevel warn
#ErrorLog /var/log/apache2/error-tes.log
#CustomLog /var/log/apache2/access-tes.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess
<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>
my route
Route::get('/', 'PenggunaController#index');
Route::post('/submitlogin', 'PenggunaController#submitlogin');
Route::prefix('workorder')->group(function () {
Route::get('inprogress', 'WorkorderController#fetchinprogress');
});
Route::prefix('request')->group(function () {
Route::get('inprogress', 'MyreqController#index');
Route::get('/myreq/{id}/{flag}', 'MyreqController#flag');
Route::get('/emp', 'MyreqController#emp');
Route::get('history', 'MyreqController#history');
});
thank you for attention

Laravel auth not working change mysite.com/index.php to mysite.com

I set up a local Laravel server for developement and push changes through Git to my production server.
I made a new Laravel project that i pused ok. Then i added php artisan make:auth on my local server and pushed to production but get 404 cant find login (or register). After some work I found out that:
www.mySite.com/login
can not be found but if I write
www.mySite.com/index.php/login it works.
So now I think I have to modify my htaccess to ignore the index.php but I cant get it to work. I tried some suggestions but none seems to work and I don't have a clue why it is not working.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase Test/public/
* RewriteCond %{THE_REQUEST} /index\.php [NC]
* RewriteRule ^(.*?)index\.php$ /$1 [L,R=302, NC, NE]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
The two lines marked with * I tried to add after reading a suggestion here on Stack Overflow (cant find the link now). I also tried
htaccess remove index.php from url
this suggestion.
Any ideas? Thanks.
Edit:
My sites-enabled/000-default.conf looks like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Test/public
<Directory /var/www/html/Test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =nfoscan.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
and my 000-default-le-ssl.conf Looks like this:
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Test/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
ServerName mysite.com
</VirtualHost>
</IfModule>
I removed the comments in configs..
I tried to add
<Directory /var/www/html/Test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
to my 000-default-le-ssl.conf but it resulted in internal server error..
First check if your apache has enabled mod_rewrite you can do it easily by
typing
apache2 -M
or even simpler:
a2enmod rewrite
if you had enabled it already you will receive message:
"Module rewrite already enabled"
If you haven't then you will receive message:
"Enabling module rewrite". You will have to restart apache.
Check if you have in you htaccess line (AllowOverride All)
<Directory /var/www/html/project/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Ok so I fixed it. There was some problem in my .htaccess file. I started with removing the .htaccess file in /Test/public and then I didnt get internal server error when messing with in 000-Default-le-ssl.conf file anymore. Then I just copied in another .htaccess file in the directory and it all worked as it should :O
Thanks to all who tried to help me!
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Posting the working .htaccess file if anyone ever have this problem again :)

.htaccess setting: Laravel Page redirect is not working

Here's is My Laravel-5.4 code that i am facing problem. I had created test laravel project with two pages home & about us and mapped the file path using Apache v-host(www.test.com)
When i hit www.test.com it loads correctly to the index page but when i try to hit www.test.com/about It showing 404 error .But when i hit like this url www.test.com/index.php/about page loads properly
I don't know its problem is in my code or Apache configuration or any other
controller:
public function index(){
return view('pages.index');
}
public function about(){
return view('pages.about');
}
Route :
// Home Page
Route::get('/','pagesController#index');
// About Us Page
Route::get('/about','pagesController#about');
Apache conf:
ServerAdmin webmaster#localhost
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/html/test/public/
.htaccess
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
You probably have an issue with mod_rewrite that is not enabled.
Try to enable it with a2enmod rewrite and then restart apache /etc/init.d/apache2 restart
Give a look to that answer.
OR
If it's not working.
This may come from Apache conf : etc/apache2/httpd.conf.
This article will explain it better than me.
You may need to edit :
<Directory "/var/www/html">
...
AllowOverride None
...
</Directory>
To
<Directory "/var/www/html">
...
AllowOverride All
...
</Directory>
And restart apache /etc/init.d/apache2 restart
OR
If it's still not working try to do some chmod 0755 on your Laravel's project.
Do you have mod_rewrite installed and enabled on apache?
In order to use mod_rewrite you can type the following command in the terminal:
a2enmod rewrite
Restart apache2 after
/etc/init.d/apache2 restart
or
service apache2 restart
This is the .htaccess I have on my public/ directory:
<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]
Also, editing /etc/apache2/sites-enabled/000-default
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

Laravel setting vhosts on XAMPP for pretty urls (routing issue)

I use XAMPP localhost server and I recently got into possession of a introductory book regarding Laravel. I'd like to configure it propery but I stumbled upon a rock.
I don't know much about routing, but I enabled mod_rewrite, and included opt/lampp/etc/extra/httpd-vhosts.conf in /opt/lampp/etc/httpd.conf using the setting that Dayle Rees recommends, that is:
<VirtualHost *:80>
ServerName my_project
DocumentRoot /opt/lampp/htdocs/my_project/public
CustomLog /opt/lampp/htdocs/my_project/app/storage/logs/access.log common
ErrorLog /opt/lampp/htdocs/my_project/app/storage/logs/error.log
<Directory /opt/lampp/htdocs/my_project/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot opt/lampp/htdocs/choqlet/
ServerName choqlet
ServerAlias localhost/choqlet
</VirtualHost>
After i've done this, due to the rerouting, I do have an access to the laravel files, but when I want to access my other projects on the localhost, I constantly get redirected to the Laravel's index. Here's the .htaccess file contents from laravel's 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>
I guess that I'm doing something totally wrong here or Rewrite rules are just screwed?

Categories