Laravel routing is not working on WAMP - php

For few days i've been searching how to resolve this issue, but nothing helped.
I have laravel project c:/wamp/www/laravel/public and only the default route is working(anything i put in it it will work), but any other route is not.
These two routes i have at the moment. First one works, second one not.
Route::get('/', function () {
return view('page.home');
});
Route::get('/shows', function () {
return view('page.shows');
});
I tried many things in .htaccess, httpd.conf, httpd-vhosts.conf that i found on the internet but nothing works.
I've enabled rewrite_module in httpd, i've tried adding virtual host to ti or httpd-vhosts:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName autoplay.dev
<Directory "c:/wamp/www/laravel/public">
Options FollowSymLinks Indexes Multiviews
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
This is my .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine on
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
In it i tried RewriteBase as well but it didn't help.
Now when i try to go to any other page except home page(it's the same if i have a route or not) i get error NOT FOUND: The requested URL /wamp/www/laravel/public/index.php was not found on this server.
Please don't ask if views are in page folder and similar questions, that is correct because it's working if i switch it in default route.
Can you please help me because i've been searcing and trying for few days and this is bad for my health :D
Thanks :)

In your virtual host file,
<VirtualHost *:80>
DocumentRoot c:/wamp/www/laravel/public
ServerName autoplay.dev
</VirtualHost>
Use below code in your .htaccess file:-
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Now check autoplay.dev/ in your browser.
Link:- https://laravel.com/docs/5.0/installation#pretty-urls
Check this link also.
Hope it will help you :)

Related

Codigniter htaccess error 404 at production

i am very begainer to server technologies.i know this question asked too many times but i really don't get it run.
it runs with domain.com/2.0/index.php/testbut when you remove index.php it throws
The requested URL /2.0/test was not found on this server.
Apache/2.2.15 (CentOS) Server at domain.com port 443
my project stucture
-
Public_html
--2.0(this is my project folder where ci can be located.it has sys,app,.htaccess)
--.htaccess
My domain
https://domain.com/2.0/
about the problem
i have two htaccess one at root mention above one is inside 2.0 folder
and the strange thing is what ever i write in the htaccess file it never effect anything
public_html/.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]
</IfModule>
public_html/2.0/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
my httpd.conf
<VirtualHost *:443>
ServerAdmin info#domain.com
DocumentRoot /home/natural/public_html
ServerName api01.domain.net
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/access_log common
SSLEngine on
SSLCertificateFile /home/natural/api01.domain.net.crt
SSLCertificateKeyFile /home/natural/api01.domoin.key
<Directory />
Options Indexes FollowSymLinks
Allow from all
AllowOverride None
</Directory>
</VirtualHost>
i search alot and follow all the answers by Stack overflow but no luck.
The directive "AllowOverride None" in httpd.conf will disable parsing of the .htaccess file within the directories specified (in this case /) -- Can you confirm that either of your .htaccess files are in fact being parsed?
If not, does modifying the Directory subsection within your httpd.conf file to:
<Directory />
Options Indexes FollowSymLinks
Allow from all
AllowOverride All
</Directory>
Solve the issue?
For more information: http://httpd.apache.org/docs/2.4/mod/core.html#allowoverride
I assume 2.0 is the new version of the site. It looks like /2.0/.htaccess is written as though it expects to be in the root folder. Try adding RewriteBase /2.0/ after engine on. You can remove it later when you replace the contents of the root folder with that of 2.0's.
The main problem is your # Handle Front Controller... rule. It'll capture any virtual URLs before they ever get to the 2.0 folder. Try changing it to this:
RewriteRule ^(?!2\.0(?:/|$)) index.php [L]
That will exclude the 2.0 folder from the current site's virtual URLs.
You do still need AllowOverride all as recommended by the other answer, and the directory should be the same as your DocumentRoot, not /.
Add this code inside root->.htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteRule ^(?!2\.0(?:/|$)) index.php [L]

Dynamic Virtual Host gives 500 error with Laravel

I'm trying to make a dynamic developing environment with virtual host.
Now i have:
<VirtualHost *:80>
UseCanonicalName Off
VirtualDocumentRoot "C:\xampp\htdocs\%1\public"
# available aliases to use
ServerAlias *.dev
</VirtualHost>
And it works for the default route of Laravel:
Route::get('/', function () {
return view('home.index');
});
But any other route will give me a 500 error of to many internal redirects.
I use Laravel 5.2 without any changes at all except for the routes.php and some default changes.
When I assign the domain like this as VirtualHost it works all just fine:
<VirtualHost *:80>
ServerName example.dev
VirtualDocumentRoot none
DocumentRoot "C:\xampp\htdocs\example\public"
</VirtualHost>
How can I fix this problem so I can use dynamic domain names so I don't have to add all domains manually.
Thank you in advance,
Stefan Fransen
Edit
When I use this:
http://example.dev/index.php/test
The page is loading correctly but this is not what I want.
So how do i remove the index.php from the url? i've checked and al modules are loaded correctly this is my .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>
Edit
Found out that when I changed RewriteRule ^ index.php [L] to RewriteRule ^(.*)$ /index.php/$1 [L]
But I still don't understand why it does work on a manual added vhost but not on a dynamically generated vhost, does someone have a explanation for that?
I guess you rewrite module (mod_rewrite) is disabled. Check it in apache.conf
Maybe section Pretty URLs can help you.
https://laravel.com/docs/5.1
I got the same problem. I found a solution for it.
Go to .htaccess file on root directory if it is not in root directory then it will be available in public folder cut from there and paste into the root directory
Change the following code.
RewriteRule ^ index.php [L]
to
RewriteRule ^(.*)$ /index.php/$1 [L]

Remove index.php from the url with laravel 5

I checked many posts here about removing index.php from url but I could not get the desired results, I already added my local url site name to virtual hosts file (I use wamp) and when I write url like this it work http://first-app.com
My problem when I navigate to another folder like "songs" this url does not work, I get url not found
http://first-app.com/songs
while if I used index.php it work
http://first-app.com/index.php/songs
here is my httpd-vhosts.conf file:
<Directory C:\wamp\www\composer-demo\first-app\public>
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "C:\wamp\www\composer-demo\first-app\public"
ServerName first-app.com
</VirtualHost>
Can that be solved from modifying this file ? or I need to modify .htaccess file located at the public folder ? here it is:
<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>
All I need was to enable rewrite_module in the apache server then restart, since I use wamp I only selected the module from the list menu
Here is a complete list how it can be done for Mac, Linux and Windows

which one is better to run laravel?

I have installed laravel in my cpanel and localhost, but i found two way to execute/run laravel.
access the
/public/
use
php artisan serve
if i run in my notebook/localhost i can use php artisan serve and it done well like routing and database, but in my cpanel i cant use the second way, so i must use first way, but it not done well like routing and etc.
So which one is better and how to make the first way run well?
Normally, you would use
php artisan serve
on your development environment only.
On production servers, you will add a <VirtualHost> or an Alias drective in your Apache configuration.
<VirtualHost *:80>
ServerAdmin admin#localhost
DocumentRoot /path/to/your/laravel/public
ServerName your.domain.com
<Directory /path/to/your/laravel/public>
AllowOverride None
Order allow,deny
Allow from All
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</Directory>
</VirtualHost>
With this type of configuration, you can access your Laravel site as:
http://your.domain.com/
When using an Alias, your Apache configuration will be something like this:
Alias /any/path/you/want /path/to/your/laravel/public
<Directory "/path/to/your/laravel/public">
Order allow,deny
Allow from All
Options +FollowSymLinks
RewriteEngine On
RewriteBase /any/path/you/want
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</Directory>
With this configuration, you will access your laravel as: http://your.domain.com/any/path/you/want
On some web hosting providers, you don't have access to the Apache configuration,
in which case, you will have to put your configuration in an .htaccess file inside your public directory.
Laravel has a default .htaccess file inside the public directory that contains this:
<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>
You will have to check if your hosting allows .htaccess

The url requested was not found laravel 4

I'm trying to create an app with laravel 4 but i'm facing a url issue. i have wamp installed on my machine. i set up a new virtual host in my httpd-vhost.conf with this code
<VirtualHost mobile.dev>
DocumentRoot "C:\wamp\www\mobile.dev\public"
ServerName mobile.dev
<Directory "C:\wamp\www\mobile.dev">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
mobile.dev is a folder and also the domain name in my localhost.
here is my Route.php file
Route::get('/','HomeController#showWelcome');
Route::post('login','LoginController#userLogin');
Route::get('login','LoginController#getUsers');
when i ask for mobile.dev/login it gives me the requested url was not found.
can you help me please solve this issue. but when i ask for mobile.dev/ its working.
Here is my .htaccess file :
<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]
Here is more details. when i remove my htaccess content everything works fine with the default url http://mobile.dev/index.php/login
So the problem is in my htaccess and the rewriting in my virtual host
It might be not Laravel problem, but seems your wamp server haven't enabled mod_rewrite in httpd.conf file yet. Locate the line -
#LoadModule rewrite_module modules/mod_rewrite.so
and remove the comment symbol '#'. Then save the file and restart Apache.
Solution:
1- when you have wamp installed in your machine please go to C:\wamp\bin\apache\Apache*.*.*\conf\httpd.conf and make sure that rewrite_mod is enabled by deleting the hash tag. (instead of using the interface provided by wamp)
2-there are two ways to enable rewriting for laravel in .htaccess file :
<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>
or using this :
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
3- if you're setting a virtual host be sure to add this option in the <virtualhost> tag
<Directory "C:\wamp\www\mobile.dev\public">
Options FollowSymLinks Indexes Multiviews
AllowOverride All
</Directory>
Thanks a lot for your time.
Have you tried
Route::post('login','LoginController#userLogin');
without the () after userLogin?
Your <Directory "C:\wamp\www\mobile.dev"> in config should be <Directory "C:\wamp\www\mobile.dev\public"> to specify the public directory to the root of the htaccess rewrite rules.
I originally thought you were missing the </IfModule> at the end of your .htaccess file but when I posted my .htaccess file it hid the </IfModule> as well so that is a stack overflow issue. Otherwise your htaccess is correct.

Categories