Laravel - unable to find new page (404 error - not found) - php

I´m looking for solution for my laravel project problem (laravel version: 6.5.2). I found a lot of similar questions, but no solution.
So, I have created new laravel project and then i put it on my hosting.
My FTP structure is:
- www
- AutsokolaIS
In www folder, I copied content of Public folder and in the AutoskolaIS other folders and files (app, bootstrap, config, etc.)
Everything was good, until I tried to create a new page linked to welcome page.
Link is mydomain.com/page. After click on this link, I get 404 error page. When I directly open the URL mydomain.com/index.php/page everything works.
I know it´s problem with .htaccess file, but I´m not able to edit .htaccess file in correct form.
Can anyone please help me?
Thank you

By default the website will be load from public folder. If you want to remove public from your url,copy .htaccess file from public folder to root and replace the code with the following..
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php

Related

Laravel 8.4 – Remove Public from URL

I am working on creating a website that converts text into speech. I am using the script from codecanyon which is Developed with PHP 7.4.x and Laravel 8.4.x . The issue I am facing is that I don't want to show /public URL as a permalink to access the website. Now, if I type mywebsite.com/pubic then the website is accessible otherwise if I write mywebsite.com then it only shows the files. I followed some of the previous queries posted on StackOverflow but got no results.
The topic I followed is Laravel 5 – Remove Public from URL
I tried even by renaming server.php , copying .htaccess and rewriting it. But those all resulted in a screen showing up errors or even blank.
My .htaccess file is;
<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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
To remove the /public from the URL you are not going to use the .htaccess file.
What you are going to do instead is set the /public folder as the serving directory for your Server.
If you use Apache, just go to your /etc/apache2/sites-available/000-default.conf file and change the DocumentRoot from {your base folder}/ (usually /var/www) to {your base folder}/public
The content of public folder should go to the public folder of your server (fe it's public_html on my server), and everything else should be stored in a different folder (fe laravel_mywebsite). Then you should go to public_html/index.php and change the folder paths based on where you put your Laravel app.
If you want to only use .htacces, you just need to rewrite all requests from /public to /
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]

Vanilla php files in subfolder with laravel - page not found error

I have a laravel app: https://laravel-app.com
I want to serve custom pages from a folder on the same domain https:laravel-app.com/player/player.php
I have set the .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /player/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /player/player.php [L]
</IfModule>
But when I try and navigate to that page by using this direct url: https:laravel-app.com/player/player.php
I get the laravel routing error: sorry, the page could not be found
Can someone explain how to get around this?
Anything you want accessible you can put in the public folder of your application, which should be the DocRoot/WebRoot. You won't need any special rewriting or rules as it will be an existing file so the server will serve it fine.

How to remove the root folder name from codeigniter application

I have my website hosted at https://www.webdomain.com/
The hosted website at the above domain IS NOT CODEIGNITER
On the server, at the location my_username/public_html/www/myproject, a Codeigniter application is hosted.
Meaning, to access a controller and its function in myproject application.
I use the following URL
https://webdomain.com/myproject/controller/function
As you may have already noticed, myproject is the root folder of the Codeigniter application
I've been trying to remove myproject from the URL, but with no luck.
I've gone through several questions on stack overflow, but as I figured it out, all of those questions refer to project directories, that are not necessarily application root directory. In my case, I want to remove the name of the root directory myproject from the URL.
This is my .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
Try this:
RewriteRule ^myproject/(.*)$ $1 [R]
This need to be in the root folder, I strongly recommend you go with #vivek_23 suggestion in the comment.
Have you try to set route in route.php file?
$route['controller/function'] = 'myproject/controller/function';
Try with .htaccess. I mainly used this on the localhost machine. This .htaccess file should be in the root of myproject folder. Here is the documentation for more information https://httpd.apache.org/docs/current/howto/htaccess.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject/
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Hope this will help to out :)

mod-rewrite RewriteBase not working correctly from root

Hi I have been following the "Build a PHP MVC Application" tutorial on Codecourse's YouTube Channel.
I have moved the project to the root(htdocs)
and now when I load http://localhost all I see is the default apache folder index.
My files are organised as such:
htdocs
->app
->public
->.htaccess
.htacces contains:
Options -MultiViews
RewriteEngine On
RewriteBase /public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Edit: if I go to localhost/home (one of the controllers i setup) it loads the page correctly
The rewritable part http://localhost/ is empty, so it does not match (.+).
It would match (.*).

wordpress 404 error when trying to acess folder on root

I have a wordpress website and within the root directory a folder called /ideal/.
The function for the /ideal/ folder is to make payments trough the website from visitors.
Everything worked well for a while, since a few days there is a problem with the page.
When i navigate to my website http://www.nibincasso.nl/ideal/ it wil show up with a 404 error.
With the release of wordpress 4.0 it looks like wordpress is trying to make some sort of dynamic link for the folder /ideal/.
However i want it to open as a static page, not by making it a wordpress dynamic page. “http://www.nibincasso.nl/ideal/index.php”.
Example of .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Can someone help me with a solution for this problem?
Kind regards,
Fabi
Update *
I created a new subdirectory on my root with a blank index.php page only saying test
This one opens fine. But when i try to enter the subdirectory /ideal/ with the index.php i get a 404 error. How come?
Try following
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ideal/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ideal/index.php [L]
</IfModule>
# END WordPress
There seems to be a problem with the php code inside the index from the /ideal/ folder.
I will search for the solution this is not a wordpress problem.
Thanks for helping me for so far.

Categories