0

On local host I was running my php (MVC) application with following rules in my .htaccess file:

Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(config|core|css|js|fonts|images|robots\.txt)

RewriteRule ^(.+)$ index.php/$1 [L]

E.g. localhost/myapp/register/login will load the log in page. But on a live server I'm having issues. The first problem I've faced was No input file specified. Reading this answer I changed this line RewriteRule ^(.+)$ index.php/$1 [L] to RewriteRule ^(.*)$ index.php?/$1 [L]. This solved the first problem but created another problem and now it's always loading the same/default view and controller no matter what the url is.

In my index.php has the following lines of code:

$url = isset($_SERVER['PATH_INFO']) ? explode('/', ltrim($_SERVER['PATH_INFO'], '/')) : [];
 // Route the request
 Router::route($url);

So, I checked the $_SERVER['PATH_INFO'] value and it's empty. Now my question is why it's empty and how can i achieve the normal behavior of the urls.

1
  • “Now my question is why it's empty” - because you changed the URL, from one that had a path info component, to one that doesn’t. Path info is the trailing part of the URL path component, that comes after the file name that could by matched to a physically existing file. But you removed that portion from the URL path, and put it into the query string instead. Commented Sep 2, 2020 at 7:03

2 Answers 2

0

So I found a solution here. I have changed my index.php as following:

$url = isset($_SERVER['REQUEST_URI']) ? explode('/', ltrim($_SERVER['REQUEST_URI'], '/')) : [];
 // Route the request
 Router::route($url);

... and now it's working as expected :) .

Sign up to request clarification or add additional context in comments.

Comments

0

It's so simple when we/I can use Laravel because it comes with .htaccess file automatically in a folder, apart of using Laravel you can use cPanel.

The .htaccess file should contain the following rules:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.+)$ index.php/$1 [L]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.