PHP Friendly URL: Does not load files from Folder

Asked

Viewed 550 times

1

I have in my root directory the index.php file and config.php. Inside the root folder of my site I have the pages folder with the home.php, login.php and Register.php files, but when I try to access them only the home.php file loads normally, the others have error in loading.

Error:

Object not found, sir! The requested URL was not found on this server. The link on this page seems to be in error or out of date. Please inform the author of this page about the error.

If you believe you have encountered a problem on the server, please contact the webmaster.

Error 404 192.168.64.2 Apache/2.4.41 (Unix) Openssl/1.1.1d PHP/7.4.3 mod_perl/2.0.8-dev Perl/v5.16.3

Follow the code for verification:

index.php file


<?php
include('config.php');

$url = (isset($_GET['url']) ? $_GET['url'] : 'home');
if (isset($_GET['url']) ? $_GET['url'] : 'home');
if(file_exists('pages/'.$url.'.php')) {
include('pages/'.$url.'.php');
} else {
include('pages/404.php');
}
?>

config.php file

<?php
define('INCLUDE_PATH','http://192.168.64.2/sistema/');
?>

Obs: I’m using shaman

  • You created a file .htaccess to configure Apache?

  • And you’re trying to access with query string or not? Ex: 1. localhost/?url=login or 2. localhost/login.

  • Yes, I have the . htacess file in the root folder. When I access http://192.168.64. 2/system/ it loads home.php normally but when I try to access login.php or Register.php it displays this error. I’ve always done so in windows and it worked, I’m currently using the shaman on Macbook. I don’t know if any configuration has to be made in httpd.conf file.

  • AllowOverride in your file httpd.conf is set to All? AllowOverride All. If not, switch to All and restart the apache.

  • Off-topic: the line of your first if ends with ; and therefore its if is not serving for nothing. This is one of the reasons that make me use always { }. But it’s everyone’s taste ;)

  • I already changed the Allowoverride to All and continues the same error x).

  • Is the Apache root directory set to the root directory of your site? I mean if you access it like this 192.168.64.2/?url=login or so 192.168.64.2/sistema/?url=login or otherwise.

  • to access the project in the htdocs folder I have to use the link http://192.168.64. 2/system/, I cannot access the direct root folder by http://192.168.64. 2/, it directs me to http://192.168.64. 2/Dashboard/. I find it strange because it would have to work by localhost:8080, but only works by ip.

  • 1

    For new visitors here goes to Conclusion of the chat: Possibly it was an Apache configuration. After installing an earlier version of XAMPP, the Urls were re-loaded correctly.

Show 5 more comments

1 answer

0

Good for you to have friendly url you must have the file. htaccess on it will get apache settings like redirect, folder permissions, when I want to use URL friendly using this setting below

RewriteEngine On
Options All -Indexes

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=/$1 [L,QSA]
  • the . htaccess file is in the project root folder. follow file: &#xA;rewriteEngine on&#xA;RewriteCond %{SCRIPT_FILENAME} !-f&#xA;RewriteCond %{SCRIPT_FILENAME} !-d&#xA;RewriteRule ˆ(.*)$ index.php?url=$1 [QSA,L]&#xA;Options -Indexes&#xA;&#xA;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.