Zend framework URL index - php

I installed Zend framework 1.11.5 I have Wamp 2.2 and running windows7.
I have a folder (mysite) inside apache documentRoot('c:/wamp/www');'mysite' folder structure is:
/application
/controllers
IndexController.php
/views
/scripts
index.phtml
bootstrap.php
/library
/public
/css
/images
/javascript
.htaccess
index.php
Issue: If I point the browser to 'http://localhost/mysite/public/' I can see my index page correctly.But if I point to 'http://localhost/mysite/public/index/' or 'http://localhost/ejoin2ED/public/index/index' I see the Wampserver configuration page (I tought this is the output of another page I have, 'index.php' inside 'c:/wamp/www' ).
Shouldnt I see the content of index.phtml instead??
thanks
Luca
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
index.php
//identify the location of th application dir in respect to
//the botstrap file's location, and configure PHP's include_path to
//include the library directory's location
define('APPLICATION_PATH',realpath(dirname(__FILE__).'/../application/'));
set_include_path(APPLICATION_PATH.'/../library'.PATH_SEPARATOR.
get_include_path());
//give the zend framework the ability to load classes on demand,
//as you request them,rather than having to deal with require() statements.
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
//retrieve the BOOTSTRAP file
try
{
require'../application/bootstrap.php';
}
catch(Exception $exception)
{
printf('Could not locate bootstrap.php');
exit(1);
}
//start using the front controller in order to route all requests
Zend_Controller_Front::getInstance()->dispatch();
bootstrap.php
//configure the site environment status
defined('APPLICATION_ENVIRONMENT')
or define('APPLICATION_ENVIRONMENT','development');
//invoke the front controller
$frontController=Zend_Controller_Front::getInstance();
//identify the location of the controller directory
$frontController->setControllerDirectory(APPLICATION_PATH.'/controllers');
//create the env parameter so you can later access the environment
//status within the application
$frontController->setParam('env',APPLICATION_ENVIRONMENT);
//clean up all allocated script resources
unset($frontController);

There is a problem with your htaccess file.
The slash at index.php is the problem
RewriteRule ^.*$ /index.php [NC,L]
Should be
RewriteRule ^.*$ index.php [NC,L]

Related

How redirect to a static page in Public dir in a Symfony5 project

I have a simple static website.
On that I build a Symfony project to have an admin panel with easyadmin-bundle and an API to retreive data with ajax on the static page.
The project structure is like this:
bin/
config/
migrations/
public/
css/
js/
index.html
index.php
.htaccess
src/
templates/
Everythings works fine but I can only access to the page when I call :
myfakedomain.com/index.html
The page myfakedomain.com is returning a 404 error
What I would like to have is an automatic redirection from myfakedomain.com/ to myfakedomain.com/index.html
I think this can be done ine the .htaccess file. This is the current content of the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
This project is deployed on heroku so I create a Procfile
web: vendor/bin/heroku-php-apache2 public/
May it come from that ?
It comes from your .htacess which redirects all requests to index.php.
Option1 - using Apache (I don't like this method because of side effects)
Exclude the existing files from the redirection.
Declare index.html as the default file instead of index.php (when calling .
Tips: apache-pack can help you. It contains an up-to-date default configuration
Option2 - using Symfony (Recommanded way):
move index.html to template/index.html
Create a controller returning a response rendering the template files
# src/Controller/HomeController.php
class HomeController extends AbstractController
{
#[Route(name:'home', '/')]
public function index (): Response
{
return $this->render('index.html');
}
}

How to solve Error 404 when deploying laravel project to Cpanel?

I'm trying to deploy my laravel (Laravel Framework 7.28.3) to Cpanel, but got a 404 error.
I uploaded my project into /public_html, modified the index.php file to point to the correct files (as below).
I think there must be some mistake in the index.php file but couldn't figure it out.
This is my first time asking my question (after searching for it several times), so hope that I will get the answer!
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
this is my file structure in File Manager:
Deploy laravel application in Cpanel
Setup 1 : - upload file to Cpanel the root directory – not the public_html.
Setup 2 : - Open the that folder and MOVE the CONTENTS of the public folder to your cpanel’s public_html .
Setup 3 : - Navigate to the public_html folder and locate the index.php file. Right click on it and select Code Editor from the menu.
and change this line
require __DIR__.'/../folderName/vendor/autoload.php';
$app = require_once __DIR__.'/../folderName/bootstrap/app.php';
NOTE : - folderName here is in root where you laravel application stay
that's it now all your request will come inside public_html folder index.php and this file will include require __DIR__.'/../folderName/vendor/autoload.php; and run laravel application
Folder structure will look like
/laravel
/public_html/index.php
indside index.php
require __DIR__.'/../laravel/vendor/autoload.php';;
$app = require_once __DIR__.'/../laravel/bootstrap/app.php'; // here laravel is folder name
You need to make sure your application is in a folder outside of your public_html.
Then you need to make a symbolic link to everything in your public directory inside your application. This symbolic link should be placed in your public_html.
This way your business logic is not available from the outside, only from your own application.
Actually it is advisable to clone your application using git and then install it following the steps in de docs. (https://laravel.com/docs/7.x/installation)
In your public/.htaccess file replaces the code given below..make sure that you uploaded your project in the root public_html folder.
<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

URL Routing in PHP : url routes ony to 404-Not-Found page

I have a php project in htdocs folder named "das-xampp". The index file in the root directory works as a router. I have another index.php inside views.
so the structure is as below:
das-xamp
|__index.php
|__views
|__index.php
|__about-us.php
|__404-Not_Found.php
So whenever someone types 'localhost/das-xampp' it should re-route the user to the index inside 'views/index.php'
My root index(the one that works as a router) is as follows:
<?php
$path = trim($_SERVER['REQUEST_URI'], '/');
parse_url($path, PHP_URL_PATH);
$routes = [
''=> 'views/index.php',
'about-us' => 'views/about-us.php'
];
if (array_key_exists($path,$routes)) {
require $routes[$path];
}else {
require 'views/404-Not-Found.php';
}
?>
The thing is whenever I type in 'localhost/das-xampp'(after turning on apache and mysql), the not-found php comes up. Even when I type 'localhost/das-xampp/about-us' manually Object not found is shown.
This doens't happen if I use
"php -S localhost:<some_digit>"
All my view works fine.
not-found page
The problem was with .htaccess file. I didn't include an .htaccess file which will re-route according to the routings I had in index.php file(the one in the root directory).
I'm posting the .htaccess code below
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /das/index.php [L]

How to remove public/index.php/ from url in Codeigniter 4

I want normal URL like www.sample.com/controller not www.sample.com/public/index.php/controller.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php/$1 [L]
My .htaccess file
Just do
Step 1: In public/ directory, copy index.php and .htaccess to your root project directory.
Step 2: In the root project directory, open index.php and edit the following line:
index.php -> $pathsPath = FCPATH . '../app/Config/Paths.php';
to
index.php => $pathsPath = FCPATH . 'app/Config/Paths.php';
okay , this is how I solved this problem :
you need 2 .htaccess files
the first one in root path "/.htaccess" of your project
the second one in the public folder "public/.htaccess"
and here is the first one "/.htaccess"
# this is my version (Nassim) of the htaccess file , I use this one in the root directory "/"
# of the project and a second .htaccess in the public directory
DirectoryIndex /public/index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./public/index.php/$1 [L,QSA]
and the second one (comes with CI installation): "public/.htaccess"
# I recommend you remove `IfModule`. Because if you need mod_rewrite,
# you don't need `IfModule`. If you don't need it, you don't need this file
# at all.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|images|assets|doc|data|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
go to app/Config/App.php and then public $indexPage = 'index.php'; change to public $indexPage = '';
works like charm
Create a file called index.php outside of the public directory and write the command
require_once './public/index.php';
That's it.
Set up Virtual hosts (if you haven't already), but make sure to point to /public directory (xampp example):
ServerAdmin webmaster#example.com
ServerName example.com
DocumentRoot "path-to-project/public"
<Directory "path-to-project/public">
Order allow,deny
Allow from all
AllowOverride All
Require all granted
</Directory>
Do not touch any .htaccess file in default CI4 distribution
Edit app/Config/App.php - $baseURL = 'http://www.example.com/'; $indexPage = '';
I've no idea how you get this .htaccess. If you download CodeIgniter 4 from here and you can see Htaccess file is different what you added.
Since there are many changes in CodeIgniter (1,2,3) to Codeigniter 4, htaccess moved to public/ folder which will set to document root and .htaccess which place outside will not valid in CI 4
Correct path to .htaccess
public/.htaccess
Note: I just tested index.php URL issue and there was no issue like that. worked/loaded fine without index.php
Project Structure codeigniter4
If Run project in Xamp show Like this
Copy public-->index.php to rootfolder-->index.php
Now run Like this in webbrowser show this like error to solve this
solution
$pathsConfig = FCPATH . '../app/Config/Paths.php';
to
$pathsConfig = FCPATH . 'app/Config/Paths.php';
Now run
create .htaccess in root folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Now you can switch your controller name without .htaccess your url must be like this http://localhost:8080/payinlinks/index.php/login
else http://localhost:8080/payinlinks/login
Step 1:
Go into Your_Project_Folder > App > Config > App.php
change to $baseURL='http://localhost/Your_Project_Name'
change to $indexPage=""
Step 2:
Go into Your_Project_Folder > Public
Copy .httaccess and index.php
Paste these files in Your_Project_Folder
Step 3:
Go into Your_Project_Folder > index.php
change, FCPATH . '../app/Config/Paths.php' to FCPATH . 'app/Config/Paths.php'
ALL DONE!!!
create a .htaccess file in /public with :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Step 1: In public/ directory, copy index.php and .htaccess to your root project directory.
Step 2: In the root project directory, open index.php and edit the following line:
change:
$pathsPath = FCPATH . '../app/Config/Paths.php';
change TO
($pathsPath = FCPATH . 'app/Config/Paths.php';)
enter image description here
have you tried this:
RewriteEngine On
RewriteBase /yoursite.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php/$1 [L]
I was able to "solve" the problem in my hostinger server in one project. After I created a new project with a newer version of codeigniter 4 I realized that I could no longer use the same solution and after hours of research I found a very simple solution.
What I did is I changed the root directory to be the public folder using the .htaccess that is located at the root folder of the project.
#RewriteEngine on
#RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC,OR]
#RewriteCond %{HTTP_HOST} ^mydomain.com$
#RewriteCond %{REQUEST_URI} !public/
#RewriteRule (.*) /public/$1 [L]
Using that trick I could load my codeigniter 4 in a live server without any problem.
Actually, I used this to configure a codeigniter 4 project inside a subdomain.
change the index.php =>
require realpath(FCPATH . 'app/Config/Paths.php') ?: FCPATH . '../app/Config/Paths.php';
to
require realpath(FCPATH . 'app/Config/Paths.php') ?: FCPATH . 'app/Config/Paths.php';
Go to app/Config/App.php and find public $indexPage = 'index.php';.
Remove index.php from this public variable and that's it.
To solve the above issue removing public/index.php from url then you should following those below steps:
Copy the index.php and .htaccess files from the public/ directory.
Add the files to the root project directory.
Change your root project directory index.php file $pathsPath = realpath(FCPATH . '../app/Config/Paths.php'); into $pathsPath = realpath(FCPATH . 'app/Config/Paths.php');
Here is the full code of index.php file:
// Valid PHP Version?
$minPHPVersion = '7.2';
if (phpversion() < $minPHPVersion)
{
die("Your PHP version must be {$minPHPVersion} or higher to run CodeIgniter. Current version: " . phpversion());
}
unset($minPHPVersion);
// Path to the front controller (this file)
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);
// Location of the Paths config file.
// This is the line that might need to be changed, depending on your folder structure.
$pathsPath = realpath(FCPATH . 'app/Config/Paths.php');
// ^^^ Change this if you move your application folder
/*
*---------------------------------------------------------------
* BOOTSTRAP THE APPLICATION
*---------------------------------------------------------------
* This process sets up the path constants, loads and registers
* our autoloader, along with Composer's, loads our constants
* and fires up an environment-specific bootstrapping.
*/
// Ensure the current directory is pointing to the front controller's directory
chdir(__DIR__);
// Load our paths config file
require $pathsPath;
$paths = new Config\Paths();
// Location of the framework bootstrap file.
$app = require rtrim($paths->systemDirectory, '/ ') . '/bootstrap.php';
/*
*---------------------------------------------------------------
* LAUNCH THE APPLICATION
*---------------------------------------------------------------
* Now that everything is setup, it's time to actually fire
* up the engines and make this app do its thang.
*/
$app->run();
In CodeIgniter version 4.2 or above you have to follow 3 steps:
1st Step:
Go to this folder
App -> config -> app.php
Update base_url with your project folder name like we do in Codeigniter 3
Like this:
public $baseURL = 'http://localhost/your_project_name/';
In case if setup ci 4 using composer then you have this type of base_url which you need to change with the above defined base_url:
public $baseURL = 'http://localhost:8080';
2nd Step:
Go to public folder and copy index.php and .htaccess files (remember copy them not cut them form here)
Then paste them on root directory
Note: Same as we remove index.php in Codeigniter 3 by creating .htaccess file on the root folder and paste related code on `.htaccess' file.
3rd Step:
Replace root folders .htaccess file code with this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Then open root folders index.php file and check line 20 or this line:
require FCPATH . '../app/Config/Paths.php';
and remove ../ from it like this:
require FCPATH . 'app/Config/Paths.php';
In case you created css js folder in public folder and connected them using base_url on views/header.php views/footer.php or views/index.php then might be it occurs problems and don't get these files because of related problems:
When we use bootstrap cdn it gives this syntax which we made local like this but because of id="bootstrap-style" this it occurs problem so remove this form this line:
<link href="<?php echo base_url();?>/public/assets/css/bootstrap.min.css" id="bootstrap-style" />
Also form other css linked file remove this type="text/css" or any id="" it occures problem.
The right way to add css link is to define rel="stylesheet" on link like this:
<link rel="stylesheet" href="<?php echo base_url();?>/public/assets/css/bootstrap.min.css" />
In my case I got bootstrap and css related problems.

Shared hosting: WordPress/laravel 5

I've develop a laravel web application, and I have to upload to a hosting that already have a WordPress application, the file system looks like this:
/..
etc/
public_html/
..
wordpress_files_everywhere
..
tmp/
tmpsite/
I have not access to root folder, online to public_html, so I've created two folder inside public-html (laravel-backend, laravel-frontend).
So What I did is edit index.php in order to point laravel-backend files like this:
require DIR.'/../laravel-backend/bootstrap/autoload.php';
$app = require_once DIR.'/../laravel-backend/bootstrap/app.php';
Also I add this function to register method on app/Providers/AppServiceProvider
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
But the page still not found, I don't know what I'missing, My suspects is that I have to configure htaccess file in order to point my domain URL to public folder, But I don't know how to do it.
Any clue?
You need to make your url point directly to laravel-frontend/public and add extra ../ in index.php file. Assuming your public seats inside of laravel-frontend:
require __DIR__.'/../../laravel-backend/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel-backend/bootstrap/app.php';
Else, just rename your public folder to laravel-frontend and replace the existing larqavel-frontend so both folders are at the root level of public_html.
Also pay attention to how you type DIR. I think in laravel index.php it's typed as __DIR__
I could fix it by configuring the .htacess file as follows (Following the indications of this link http://enkognedo.com/internet/hosting-and-websites/89-multidomain.html)
RewriteEngine On
RewriteCond %{HTTP_HOST} wordpressUrl$ [NC]
RewriteCond %{REQUEST_URI} !/.*$
RewriteRule ^(.*)$ /$1 [L]
RewriteCond %{HTTP_HOST} laravelAppUrl$ [NC]
RewriteCond %{REQUEST_URI} !^/laravel-frontend/.*$
RewriteRule ^(.*)$ /laravel-frontend/$1 [L]
i really don't kwow if this has any security problem, by solve my issue.

Categories