user3185970
user3185970

Reputation: 69

Uploaded a s PHP site to the web, only index page works

I uploaded my site for the first time to an ipage hosting. There was no public_html folder, and the root directory is actually public so I uploaded all of my website folders to it, and gave open viewing permissions only to my public files. Now my home page is working and the rest of the isn't and I think it has something to do with the location of the files that is now different than when it was local, because of the structure of the ipage directories. The error I get is 'Page not found'.

This is an example from my route.php file:

Route::get('/', 'PagesController@index');
Route::get('store', 'StoreController@index');

(home page works, store doesn't).

Controllers example:

class PagesController extends MainController
{
public function index()
{   
    self::$data['title'] = 'Ayala & Tamar | Home Page';
    return view('content.home', self::$data);       
}


 class StoreController extends MainController
{
//Getting dynamic categories
public function index()
{ 
 self::$data['title'] = 'Ayala & Tamar | Store';
 self::$data['categories'] = Category::all()->toArray();
 return view('content.categories', self::$data);   
}

All my Laravel and PHP structure stayed the same and is in the main project directory, except for the public files which are no longer in the public folder, they are directly in the main directory.

Does anyone have an idea for a solution? Thanks!

Upvotes: 1

Views: 119

Answers (2)

Aykut CAN
Aykut CAN

Reputation: 95

From this first thing came in my mind : you doesn't redirect all requests to index.php

Check .htaccess file and mod_rewrite extension if you are using apache, if you are using nginx check site configuration. It must be properly redirecting all request to index.php otherwise your request wont work other than index.

.htaccess file from fresh laravel 5.3

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}]

for nginx you should something like this in your site config file:

try_files $uri $uri/ /index.php?$query_string;

location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

of course a nginx configuration can be different. Read manuals and configure them correctly.

Upvotes: 0

Komal
Komal

Reputation: 2736

Set route like this, so your route.php file look like this

Route::controllers([
  'store' => 'StoreController'
]);

Route::get('/', 'HomeController@index');

Your controller

class StoreController extends Controller
{
  public function getIndex(Request $request)
  {
    self::$data['title'] = 'Ayala & Tamar | Store';
    self::$data['categories'] = Category::all()->toArray();
    return view('content.categories', self::$data);   
  }
}

Upvotes: 3

Related Questions