April 13, 20206 yr Hi! I am novice when it come's to Webdesign, so please forgive me if I come across as a little unlearned. In my Directory Root File, I had created, amongst the typical, images folder, css folder and scripts folder and etc, an pages folder. I created the pages folder for the the purpose of keeping my files well organized. I have created both the 'Index . php' and 'contact . php', so far running both on my localhost is working like a charm. But when I tried to place the 'contact . php ' page in the pages folder, I am unable to link to it from my 'index . php' page. I get the following error: Quote Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 I should add that I created a 'header. php' and 'footer.php, placing them in an includes folder. I had placed a link to the 'contact . php' page' in my 'footer. php' include file. It looks as follows: Quote <footer> <a href="pages/contact.php">Contact</a> </footer> </body> </html> Also, here is my 'header . php ' include file: Quote <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><?php echo "$pagetitle";?></title> <meta name="description:" content="X"> <meta name="keywords:" content="X"> <link rel="stylesheet" href="build/styles/normalize.css"> <link rel="stylesheet" href="build/styles/global.css"> </head> <body> <nav> <ul> <li><a href="index.php">Home</a></li> </ul> </nav> And my 'index . php' page: Quote <?php $pagetitle = "Home"; include "inc/header.php"; ?> <?php include "inc/footer.php"; ?> My question is, am I NOT allowed to place the 'contact . php' and others, inside a sub folder within the root? And if I can, how can I link to it? Thank you!
April 13, 20206 yr You can place the files where ever you want you just need to reference them correctly. If you are in the same folder then you don't need anything in front of the file name i.e. "index.php" or "contact.php". If you had a sub folder called products in you pages folder and you wanted to reference your contact.php file you would use "/pages/contact.php". The / takes you back to the top of the tree. You can also use "../contact.php" which take you up one level. Hope that helps. Edited April 13, 20206 yr by nahosting typo
April 13, 20206 yr Author 16 minutes ago, nahosting said: You can place the files where ever you want you just need to reference them correctly. If you are in the same folder then you don't need anything in front of the file name i.e. "index.php" or "contact.php". If you had a sub folder called products in you pages folder and you wanted to reference your contact.php file you would use "/pages/contact.php". The / takes you back to the top of the tree. You can also use "../contact.php" which take you up one level. Hope that helps. Thank you for your advice, BUT! Quote Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. I get the same result. Your advice: Quote <footer> <a href="../contact.php">Contact</a> </footer> </body> </html> And I tried it this way too: Quote <footer> <a href="pages/contact.php">Contact</a> </footer> </body> </html> Still didn't work.
April 13, 20206 yr Or maybe It’s because /pages/ isn’t a folder in /inc/ Try: href=“./pages/contact.php” Or just move the included to the top level folder. Edited April 13, 20206 yr by fisicx
April 13, 20206 yr Author I used pages, but accidentally put page, but it was pages. now i'm getting this: http://localhost/project01/pages/contact.php Quote Warning: include(inc/header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\project01\pages\contact.php on line 3Warning: include(): Failed opening 'inc/header.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\project01\pages\contact.php on line 3Warning: include(inc/footer.php): failed to open stream: No such file or directory in C:\xampp\htdocs\project01\pages\contact.php on line 7Warning: include(): Failed opening 'inc/footer.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\project01\pages\contact.php on line 7
April 14, 20206 yr You need to use "/inc/header.php" as just inc/header.php is then expecting the inc directory to be in the pages directory.
Create an account or sign in to comment