Laravel 404 error with xampp - laravel

I am starting to learn how to work with laravel but got a problem. When I go to: http://localhost/testing/public/ I get a working page but when I typ for example http://localhost/testing/public/home which is one of my views I get a 404 error. Does someone know how to fix this?
Edit:
I am using the latest version of laravel and when I do for example:
Route::view('/home', 'home');
In my routes/web.php I get that error

This is more likely a problem with virtual Hosts, try the following:
First edit your route to :Route::get('/home', function(){echo
"hello"});
Then try to access: http://localhost/testing/public/index.php/home
If it works then its certainly because you don't have a virtualHost, you can set it easily in your Xampp config and modifying ur hosts file
First go to C:\Windows\System32\drivers\etc\hosts and add a new
line like: 127.0.0.1 yoursite.local
Then go to where xampp is installed under
xampp\apache\conf\extra\httpd-vhosts.conf
Then add a virtual host in the bottom of the file like:
<VirtualHost *:80>
DocumentRoot "PATH_to_laravel_folder/public"
ServerName yoursite.local
</VirtualHost>
Then you can access your route by typing: yoursite.local/home or
yoursite.local:80/home
Hope it helps you guys :)

It may be because of routes.
after creating a view you have to add it in routes/web.php
like Route::view('/yourUrl', 'viewName'); in 5.5 version.
for 5.4 or older versions Route::get('/yourUrl', 'viewName');
after adding this to routes/web.php. you can access http://localhost/testing/public/yourUrl
you can find more here

If http://localhost/testing/public/index.php/home works, try to create a .htaccess file in public directory with:
RewriteEngine On
RewriteBase /testing/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Run $ composer install in you command line

Related

Laravel root directory not public on Hostinger hosting

I currently host my Laravel website on Hostinger, but when I have a image on my page, the url doesn't go to website.com/public/img_url, but it goes to website.com/img_url, does anyone know how this works on Hostinger, and how I can fix this?
Currently my whole project is in my public_html, with no other folders besides it.
The right solution was changing my htaccess to:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
You should need to add a public inside asset function to access a public folder on the shared hosting server.
So you need to change the fetch path of files Example: asset('user/photo.jpg') to asset('public/user/photo.jpg') in each line of code where you need to fetch files from the public directory.

Apache 2.4 config include files appear to be ignored

I have an apache2 site config that works perfectly. When I place some of the directives into an include file the rewrites are no longer processed.
They all work when in a single conf file.
mod_info http://{server name}/server-info shows the directives loaded when either a single file or with include files.
If an include file has the wrong name or wrong permissions apache2 fails at start.
Single conf file or with multiple includes passes apachectl -t syntax check.
Example code is
<VirtualHost *:80>
.....
include /etc/apache2/includes/site80.conf
</VirtualHost>
site80.conf has:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteRule .* - [E=junk:1,L]
I can find nothing else required to make the includes work, and apache appears to load them according to mod_info.
Can anyone shed any light why the includes appear to be ignored?
Thanks

C:/xampp/htdocs/.htaccess: RewriteRule: bad flag delimiters - XAMPP/Windows

I installed XAMPP on my Windows PC.
I created a simple static pages and created .htaccess file in c:\xampp\htdocs.
.htaccess file content is:
RewriteEngine On
RewriteRule ^about-us$ about-us.php [L]
I am getting 404 for the below page:
http://localhost/mysite/about-us/
Anyone help me to identify whats wrong with the .htaccess file.
It worked when I moved my .htaccess file from htdocs to htdocs/mysite

Transferring codeigniter HMVC project from localhost to live server

I made a web application on codeigniter HMVC. I tested it on local server and the following link works perfectly fine by giving me a login form, the link : http://localhost/bird_vision/users/login, where my directory structure goes like this bird_vision/application/modules/users/users.php (users->module's name, users.php->controller's name). Now I posted the whole "bird_vision" folder to web using filezilla.
- changed the base_url in config.php file to domain_name
- Made some changes in .htaccess file
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$10 [L,QSA]
</IfModule>
Now when I write bird_vision.se/bird_vision/users/login in my address bar it gives me 404 page not found. Although when I when type birdvision.se/bird_vision/welcome it gives me welcome to codeigniter page.
Please I need help as my all hardwork making this project is at stake. Thanks in advance.
I figured the problem was not with HMVC but was with codeigniter version 3.0. When it comes to unix(which was the operating system running on my server), it is case sensitive. So when I tried to access the controller it could'nt find the file because of case sensitivity and a 404 popped out everytime.
My folder structure before was something like :
-application
-->modules
--->users
---->controllers
----->users.php
And the link on which I was getting 404 was www.example.com/users/login
where "users" in the link is controller's name within the "controllers" folder under "modules" folder in my case named as users.php and "login" is the function inside the controller.
All I had to do was to change the case of the first letter of my module and controller name. Now my directory looks like
-application
-->modules
--->Users
---->controllers
----->Users.php
note : capitalized "U" in Users module and Users controller.
And the the url I used to access the users controller was : www.example.com/Users/login
And I was back in business.

How to use mod_rewrite in Apache2?

I´m trying to do a simple redirection with Apache2 with mod_rewrite. I've installed the module in my Apache and I´ve set a webpage in localhost/file1/file2/page.html. I´m writing this in my 000-default file:
RewriteEngine On
RewriteRule elegantdirectory/page.html file1/file2/page.html [L,NC]
So now if I try to access to localhost/elegantdirectory/page.html, the server is supposed to show me the page.html I have in file1/file2. Any ideas why isn't it working?
Try including bounds and a leading slash in your RewriteRule:
RewriteRule ^/elegantdirectory/page.html$ /file1/file2/page.html [L,NC]

Resources