Problems with Multiple Applications Setup in Codeigniter 3 - php

I know this question has been asked numerous times but couldn't find the definitive solution to what I am trying to do.
I am trying to serve multiple apps using single codeigniter 3 installation simultaneously. Specially frontend, backend and other vendor specific interface. This is required because each app has its own login and need to maintain its unique session.
I have gone through codeigniter 3 manual
https://www.codeigniter.com/userguide3/general/managing_apps.html#running-multiple-applications-with-one-codeigniter-installation
I have setup my app this way as suggeted
appfrontend
appbackend
As suggested, I have two index files which routes to each application.
index.php -> appfrontend
admin.php -> appbackend
As suggested in documentation
https://www.codeigniter.com/userguide3/general/urls.html#removing-the-index-php-file
My ".htaccess" file have
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This removes the index.php for frontend and that's fine.
Question: How to remove admin.php as well from the URL?

Related

Using both Laravel and non-laravel-PHP

I am trying to make Laravel work with a non-laravel script.
I need Laravel to handle only routes that are set in the web.php file, and allow anything else that's not defined to be handled by my non-laravel-PHP's legacy_index.php.
This is the folder setup that I have in my public.
legacy_index.php is the one that belongs to my non-laravel-php script. The legacy_index.php script has a URL parsing algorithm in it.
I want Laravel to allow me to use the legacy_index.php if the path I am trying to access is not declared in the routes, but without showing the legacy_index.php file in the link.
As an example:
Laravel would process these routes:
127.0.0.1:8000/api/getUserData
127.0.0.1:8000/api/getAppointments
But would ignore these routes:
127.0.0.1:8000/mail
127.0.0.1:8000/user-profile
And would let my legacy_index.php to handle the routing for these two.
I have tried by editing the .htaccess file, trying to redirect to these links from the routes, but nothing worked.
Did anyone do this before and has any tips/pointers?
I am developing on Windows, using Laravel 8.42.
It looks like your routes are neatly identified by the a simple rule that if they begin with "/api" then you want Laravel's index.php to handle it but if it doesn't then you want legacy_index.php to handle it. Therefore adding another conditional rewrite rule to the .htaccess might be 1 method.
...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/api/(.+)
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index_legacy.php [L]
Migrating Legacy Web Applications to Laravel might be useful to you.
See Step Three: Hand Off to Legacy Framework

Make website appear on Google regardless of PHP routing

Over the past few days, I have been working on a new website. As of now, I have chosen to go with something similar to that of an MVC: I am using PHP for routing to other pages depending on a value retrieved by GET, changing some settings inside the .htaccess.
When I search for my website on Google, I find three links: one for the website and two for different subdomains:
www.example.comsub.example.comone.example.com
The structure of the links on my website looks like this, because of the routing:
www.example.com/test/bedev.example.com/that/this
This is my .htaccess in case you need it:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
RewriteBase /
All the different parts of the website are linked together with a href, but I worry that may not be enough to make it fully SEO.
Is this a problem going to be a problem? Is there anything I can do about it?
Edit: what I am asking is whether or not this type of layout will be a problem regarding SEO. If that is the case, my follow-up question is what way I would go about fixing it, which most certainly would be a programming-related task (and so the question is not off-topic).

htaccess for domain and subdomain with laravel

I'm trying to figure out how to set up a domain and subdomain to work on a shared hosting account. It is a Laravel 5.1 application.
My access file is
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ index.php [L]
I just purchased another domain and added it on, but I get a 500 error. I renamed the access file and then it worked. So it has something to do with the access file. Essentially I want two separate domains with and I'm wanting two separate laravel applications, one for each.
I'm not familiar with atacceess.
Maybe, you get a redirect loop, because the rule isn't protected by a condition. Although the default htaccess of Laravel should already contain them.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Olaf Dietsche's answer does work for me.
Here is another thing I came upon a website that also worked just before I saw his post. I guess I was reading that this would send a 404 to that directory.
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ index.php [L]
RewriteCond %{HTTP_HOST} ^(www.)?main-topdomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/subdomain-folder/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
So along with this comes another question if anyone is in my boat. I have my subdirectory inside of my root directory.***
dlaugh.com/public_html
laravel folders and access**
inluding
app
bootstrap
config
database
etc...
but also I have my sub folder
app
bootstrap
config
database
etc...
**mysubdomain in that folder**
Is it better practice to put
-main_domain_folder and
-subdomain_folder
in public_html
and then the
/app
/config
/database
would be in the main_domain_folder rather than passing the subdomain through the main domain?

is .htaccess is good for creating yii admin panel?

I am creating an application with Yii Framework and want to redirect http://mydomain.com/yiiframework to http://mydomain.com/yiiframework/default so i created .htaccess file and i put this content on it but it don't redirect anything :
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /default/index.php [L]
my questions are :
1 - what is wrong in my htaccess file ?
2 - is that a good way to create admin section and put other stuff in default folder ?
Edited :
I accidently find it out ,i changed .htaccess to this :
RewriteEngine on
RewriteRule ^$ http://mydomain.com/yiiframework/default/index.php
and it server my purpose , but the mystery is :
^$
shows the start of line and the end of the line , what this Regular Expressions means?
to create admin-panel best practice is to create separate application for backend and frontend, which share common things with fontend, backend as in this boilerplate,https://github.com/clevertech/YiiBoilerplate
or
you sholud create single application and devide it into modules, each module have code for both frontend and backend as you see this in many yii based open source applications like Zurmo, Yupe CMS, X2Engine,
i would prefer second approach which is modular and maintainable code, slightly hard but best

How to place zend framework application in a wordpress website

Recently I created an application (sales portal) in PHP for a small company. The company had a website developed in word press. Since I hadn't worked with word press the way I embedded my application in the website is I simply created a sub directory on the host and uploaded my application there. E.g:
domainname.com - their website
domainname.com/portal - is where my application is placed (the 'index.php' file).
Since a month I am learning Zend Framework 1.8 and I want to rewrite the portal in Zend framework since I wrote the portal from scratch and its core is not as secure as it would be if it implements the Zend framework.
My question is can I include the Zend framework application into the wordpress website the way I did it with 'from-scratch' application, by creating a sub directory on the host and upload the application there? And if yes how should I configure the Zend application so that it recognizes 'domainname.com/portal' as the domain name (as home directory).
The problem that I face right now is that when I type http://www.domainname.com/portal/sales it returns 404 because there is not such directory on the server. Of course what I mean with the above mentioned link (domainname.com/portal/sales) is:
site: domainname.com/portal
controller: sales
action: index
I tried 'domainname.com/portal/index.php/sales' but when someone opens the portal with this link 'domainname.com/portal/' the next linked that is clicked (e.g. domainname.com/portal/sales) shows 404.
(note: the website http://www.domainname.com should be accessible also)
Thanks in advance.
I believe that wordpress ues a .htaccess to redirect all URLs to its index.php.
This is the .htaccess I pulled out of a test installation:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
In your case, you would need to modify the .htaccess file so that it does not care about what's in http://domainname.com/portal.
In your case, your .htaccess file could look at this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} "/portal/"
RewriteRule (.*) $1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
Basically, what this does is that it ignores the subfolder 'portal' and doesn't process it with any of the normal rules.
However, there might be a down side: If future versions of wordpress updates the .htaccess file, then you will need to make those changes to the file again.
[C]an I embed the Zend framework application into the wordpress website the way I did it with 'from-scratch' application, by creating a sub directory on the host and uploading the application there?
Yes you can.
[H]ow should I configure the Zend application so that it recognizes domainname.com/portal as the domain name (home directory)[?]
Sure, please see Base Url and Subdirectories­Docs how you need to configure your request/routing for your Zend Framework based application.

Categories