codeigniter 3.1.9 with apache and php 7.2 - routing/redirect issues with symbolic links - codeigniter-3

SCENERIO:
Recently I migrated CodeIgniter from 2.4 to 3.1.9 along with PHP from 5.2 to 7.2. Also, created a new httpd.conf file in apache. When I go to the site's URL, it loads the default page fine and I can browse to default or root
pages without any issues. There are multiple sub-domains that are mapped in routes.php to the main httpd root directory /var/www/html. These sub-domains have a symbolic link to /var/www/html, and within assets folder are
the customization files for each sub-domains.
Root HTTPD directory "/var/www/html" structure
application assets
test1 -> /var/www/html
test2 -> /var/www/html
index.php
system
URL is set as follows in config.php.
$config['base_url'] = 'https://example.com/';
Below is my entry in routes.php:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['home'] = "home";
$route['select-product'] = "home/select-product";
$route['test1/select-product'] = "home/select-product";
$route['test2/select-product'] = "home/select-product";
Please check the below image for httpd directory config:
enter image description here
PROBLEM:
When I browse to https://example.com/ it loads everything correctly.
When I go to https://example.com/test1 ==> First page loads correctly. But when I press next, the second page defaults back to 'https://example.com/';. Somehow, it looses /test1 from the browser.
Not sure if this is caused by CodeIgniter URL routing issue or something to do with httpd.conf file of Apache. The same "routes.php" file was working fine on the old server.
The routing/pagination seems to have broken after I set $config['base_url'] = 'https://example.com/';. If left empty, it takes a while for the site to load, and when it does the forms and images are not loaded correctly.
I have spent lots of hours trying to figure out the problem. I am hoping someone genius out there will be able to show be in the right direction.
Thank you.

I had this problem when I upgraded to PHP 7.2, the best solution is ,
for things to work in CI with PHP7.2,
Find and comment out(or remove) the following code from sessions.php (system/libraries/session/session.php) and place it in your index.php at the top.
session_start();
ini_set('session.use_trans_sid', 0);
ini_set('session.use_strict_mode', 1);
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.hash_function', 1); ini_set('session.hash_bits_per_character',4);
and for .htaccess, use this
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|.well-known|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1
set your uri protocol to AUTO
$config['uri_protocol'] = 'AUTO';
$config['index_page'] = '';

Related

How to change the Public directory path in Lumen?

By default Lumen "same as Laravel" has myApp/public directory to put all the public files (assets).
I want to change that directory path from myApp/public to myApp/src/custom/public. How can I do achieve this?
I also struggled with this and found a soltuion elsewhere.
I wanted the following directory structure:
.hosting root dir
├── lumen_app_dir <---
├── other_app_dir
├── etc...
└── public_html
└──lumen_app_public_dir <---
So I did the following:
Copied the index.php and .htaccess from lumen_app_dir/public to the lumen_app_public_dir.
Changed the index.php there like this:
$app = require __DIR__.'/../../lumen_app_dir/bootstrap/app.php';
$app->run($app['request']);
The important part here is, that I had to include $app['reqest'] as the parameter for run function.
And it just works without any change in the default .htaccess file. I can access the Lumen installation at server.dev/lumen_app_public_dir
Got the same problem, and solved it. Look here, maybe it will help you.
I have done this solution for my Lumen application, which works for me.
UPDATE
Ok, let's go proceeding some changes to make the system to work with your tree.
Add a .htaccess file in the root of your application so in the directory myApp\. Write it in :
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ src/custom/public/$1 [L,NC]
Assuming that you have configured your vhost pointing to \Path\myApp, we now accede to the index file of myApp\src\custom\public\. If we didn't make any mistakes, then we should get to a page that indicates an error, telling us that the bootstrap/app.php file is not found. Logic.
We must therefore change the index.php file in the directory myApp\src\custom\public :
Change from this :
$app = require __DIR__.'/../bootstrap/app.php';
To this :
$app = require __DIR__.'/../../../bootstrap/app.php';
You can now get your home page directly from the path wanted.
You can override your public directory using the IoC container like this:
App::bind('path.public', function()
{
return base_path().'/public_html';
});
But I prefer to use a symlink to the public folder like this:
ln -s public public_html
I believe you should "point" your vhost to the new location (assuming you moved/renamed the public dir to your desired path). This is only needed is your server is not yet configured this way.
Then open the index.php from your new location and "fix" the path to bootsrap/app.php
Then open server.php from the Lumen base dir and edit your paths in both locations you find "public" mentioned.
Didn't really test this but looks like it should work. Give it a try.
One solution is to bind the path fro public in the appServiceProvider.php register method:
$app->bind('path.public', function() {
return __DIR__; });
A reliable way is to go into your public_html/index.php!
I'm using Lumen 6.x and it's work properly.

Redirect root domain homepage to another domain subdirectory

I would like to:
Redirect www.olddomain.com to www.newdomain.com/page
Redirect www.olddomain.com/article1 to www.newdomain.com/article1
Here is what I put into my htaccess file:
redirect 301 / http://www.newdomain.com/page
redirect 301 /article1/ http://www.newdomain.com/article1
The first redirect works, however, the second one does NOT work, since www.olddomain.com/article1 redirects to www.newdomain.com/page/article1, which does not exist and thus returns a 404 error.
How to redirect the old domain home page (root) to a new domain subdirectory, without affecting all other redirects?
In .htaccess code should look like that:
RewriteEngine On
RewriteRule ^/$ http://www.newdomain.com/page [L,R=301]
RewriteRule ^/article1/$ http://www.newdomain.com/article1 [L,R=301]

Joomla after SEF " Page Not Found " 404 Error?

I am trying to open URL of article from Facebook page on my website but the problem is every time error 404 is raised although the article is exists .
After searching I find that there is problem in .htaccess codes and I need help in this.
The problem :
URL : like from facebook page
Website : worked like Real link
As you can see there different between this two links.
The part is added "component/content/" and without the another language prefix "ar".
Some Details :
This is my .htaccess file :
> ##
# #package Joomla
# #copyright Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved.
# #license GNU General Public License version 2 or later; see LICENSE.txt
##
##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
##
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
## Mod_rewrite in use.
RewriteEngine On
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##
RewriteBase /
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
# Forward to sitemap
Redirect /sitemap.xml http://www.businesstendersmag.com/ar/?option=com_xmap&view=xml&tmpl=component&id=3
## End - Joomla! core SEF Section.
That's all! Any help will be appreciated.
How do you generate URLs that are posted to Facebook?
Are you generating URLs like this?
// require com_content router.
require_once (JPATH_SITE.'/components/com_content/helpers/route.php');
// generate link.
$link = JURI::root() . substr( JRoute::_( ContentHelperRoute::getArticleRoute( $article->slug, $article->categorySlug ) ), strlen(JURI::base(true)) + 1);
// Where $article->slug & $article->categorySlug are fetched from database.

Ez Publish Unable to get REST API working

I am new to Ez Publish, I would like to make the default Rest API working as a first step and next developing my own Rest API extension for mobile communication purpose but I am blocked at the first one.
when I try to get the result from "www.mydomain.com/api/ezp/content/node/2/list" I get "{"error_message":"Not Found"}"
configurations are done:
setting/override/site.ini.append.php
[ExtensionSettings]
ActiveExtensions[]
ActiveExtensions[]=ezprestapiprovider
...
extension/ezprestapiprovider/settings/rest.ini.append.php
<?php /* #?ini charset="utf-8"?
[ApiProvider]
ProviderClass[ezp]=ezpRestApiProvider
[Authentication]
RequireAuthentication=disabled
*/ ?>
.htaccess
DirectoryIndex index.php
RewriteEngine On
RewriteRule api index_rest.php [L]
RewriteRule ^index_rest\.php - [L]
...
I apologize for my English.
Edit1: Ez Publish version 4.5
Edit2: It seems to be a problem of RewirteRule, when I change "www.mydomain.com/api/ezp/content/node/2/list" to "www.mydomain.com/index_rest.php/api/ezp/content/node/2/list" it works , how can I fix that ?
Edit3:
I tried all rewriterules below, still not working except the last one.
# RewriteRule ^/api/ /index_rest.php [L]
# RewriteRule ^api/(.*) /index_rest.php/$1 [R=302,NC]
# RewriteRule ^/api/(.*) /index_rest.php/api/$1 [NC,L]
RewriteRule api index_rest.php [L]
But it seems to create conflit when I try to add new extension...
I added a new extension and when I try to access to it I got an error on the log file:
Unexpected error, the message was : The API provider 'mobile' could not be found. in mydomaine.com\kernel\private\rest\classes\rest_provider.php on line 37
Try replacing those rewriterules with the one specified by eZ
RewriteRule ^/api/ /index_rest\.php [L]
This is listed here for version 4.5: http://doc.ez.no/eZ-Publish/Technical-manual/4.5/Installation/Virtual-host-setup
I just regenerate autoload and it's working now. I use cmd line to do it (regenerating autoload with admin module does not work for me).

Blank home page after creating Zend index.phtml

I am just starting with Zend and am having an issue wherein browsing http://localhost renders a blank page. I've set httpd.conf documentroot to /var/www/HTML/public and enabled Zend_layout in bootstrap.PHP. My index.phtml is locatrd in the suggested directory per the .ZF manual.
Does IndexComtroller have to specifically call my index.phtml view? What other things should I check?
Thanks Much!
EDIT: I checked httpd.conf and noted mod rewrite is enabled. .htaccess file in /var/www/html/public has ReWrite Engine ON etc. I've not created a VirtualHost entry in httpd.conf. I simply defined DocumentRoot "/var/www/html/public" Is a virtualhost required to run the framework?
EDIT2: I used php -f /var/www/html/public/index.php and received the following
PHP Warning: require_once(Zend/Application.php): failed to open stream: No such
file or directory in /var/www/html/public/index.php on line 18
PHP Fatal Error: require_once(): Failed opening required 'Zend/Application.php'
(include_path=':.:/usr/share/pear:/usr/share/php') in /var/www/html/public/index.php
on line 18
The first thing to do is make sure you have the appropriate error reporting enabled for development. Make sure these are set in your application.ini file
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
Once you've done this, re-test and post back any error messages you receive.
It seems that you did not setup Zend Framework in your include_path - did you copy the Zend-subdirectory of the installation packages libs-folder into /usr/share/php, so that you now have a directory called /usr/share/php/Zend/?