Codeigniter Installation Moved - php

I recently moved my codeigniter application from a subdomain to operate under my domain.
Basically I moved it from:
https://account.mywebsitehere.com
To:
https://mywebsitehere.com/account
Now when I try to access anything like /invoices it removes the /account from the url and results in a not found page. I have changed the base url in the config file but it is still resulting in this error.
Other than going through the entire application and changing every link to be /account/... How can I make the application work under the /account in the url?
My .htaccess file located at public_html/panda/.htaccess is as follows:
RewriteEngine on
RewriteCond $1
!^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mywebsitehere.com/panda/$1 [R,L]\

Try to change base_url to:
$config['base_url'] = 'https://mywebsitehere.com/account';

just put that code in .htaccess file and try it
RewriteEngine On
RewriteBase /account/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

first, upload an image to the root directory and see if you can access it within the browser.
if you cant access it , check your server's configuration and your .htaccess file.

Related

.htaccess file not working properly in the sever

I'm developing a web site using Codeigniter 3.X. my issue is that it works fine in localhost. now i uploaded the same to my server but it shows some error like "The page you requested was not found."
my htaccess file looks like this:
RewriteEngine On
RewriteBase /fold1/mainfold/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 ^(index\.php|robots\.txt|favicon.ico|images|smileys|js|assets|css)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /fold1/mainfold/index.php?/$1 [L]
what is issue with this code ? please help me...
Check the flowing:
Does the paths exist on your server?
Is mod_rewrite enabled on your Apache?
This code for hiding the index.php file .
And for Controller and method better to use route.php file.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I found the reason behind the issue. am using codeigniter3.X .Its file naming rules says that controller and model name should be starts with capital letter. i renamed my controller and model files. now the issue is resolved.
try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Codeigniter .htaccess redirect and hide URL part

I wish to have two Codeigniter installations one in my default root root/ and one in root/en. Problem is in my .htaccess file and in the location of default controller. Everything works in my default install, I have the default/front controller in the following directoy: root/public/index.php and my .htaccess looks like this in order to redirect and remove "public" from the url:
RewriteEngine on
RewriteBase /
ReWriteCond %{REQUEST_URI} !public/
ReWriteRule ^(.*)$ public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
Everything is fine in root, server automaticly redirects to root/public/index.php folder and reads "index.php" there, .htaccess then hides the "public/index.php" part of the url.
How can I write similar .htaccess file, so that when the user types the url "sitename/en" it automaticly redirects to root/en/public/index.php and hides the public/index.php part?
try using any of the following :
RewriteEngine on
RewriteBase /demo/
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
make sure config.php file has
$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/projectname";
$config['uri_protocol'] = 'PATH_INFO';

Rewriting URL in CodeIgniter

I want to rewrite URL using .htaccess in codeigniter but it's not working. Can you please figure it out. Want to change URL from:
www.site.com/mauritius_holiday_rentals/apartment/anyname
to
www.site.com/mauritius_holiday_rentals/anyname
My current .htaccess file contains:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteRule ^mauritius_holiday_rentals/([A-Za-z0-9-]+)/?$ mauritius_holiday_rentals/apartment/$1 [L,QSA]
First four line is for removing index.php from URL which is working fine.
If routes file is set to access new url and you want to set redirection for old URLs then Use following code in .htaccess. otherwise let me know in detail what you want to do.
RewriteEngine on
RewriteBase /
RewriteRule /mauritius_holiday_rentals/apartment/$1 /mauritius_holiday_rentals/$1 [R=301,L]
Routes.php config file code
$route['mauritius_holiday_rentals/(:any)']="mauritius_holiday_rentals/apartment/$1";
Let me know if any problem.
RewriteEngine On
RewriteBase /yourProjectName/
RewriteCond $1 !^(images|stylesheets|javascript)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourProjectName/index.php?/$1 [L]
Try to use codeigniter routing system
https://www.codeigniter.com/user_guide/general/routing.html

remove index.php with alternative routing in codeigniter

I'm working on a project in Codeigniter that doesn't use the standard routing.php file.
It calls the functions like this: test.vi/index.php/controller/function.
My goal is to remove the index.php from the url with a htaccess rewrite:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
And also this config.php change:
$config['index_page'] = '';
My question is do I need to route all the controllers/functions in my route.php or can it be done without using the route.php file?
first make sure you enabled mod_rewrite in httpd.conf:
to do so add/make sure it exsits this line
LoadModule rewrite_module modules/mod_rewrite.so
then create .htaccess in your codeigniter root folder (next to index.php file) not application folder.
.htaccess
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|img|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
codeigniter take care of all routings for you; so for
controlers/welcome.php method=hello u can access it by
http://localhost/welcome/hello
its not like laravel you need to specifically add route; codeigniter automatically Fitch controller for you. unless you have it stored in a different location or inside subfolder then you dont need to touch route.php except for setting your default route.
Here's my redirect in .htaccess for a live codeigniter site. The second part exempts certain directories.
#Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond $1 !^(index\.php|phpinfo\.php|test\.php|example\.php|images|i|css|js|beta|captcha|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
THIS works perfect for me... give it a try..
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test.v/index.php?/$1 [L]
I guess everyone forget about add test.vi folder name on .htaccess

.htaccess file is not working

RewriteEngine on
RewriteCond $1 !^(index\.php|img|css|gallary|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Above is the code exist in .htaccess.
I want the rules such as every request made to main domain or subdomain must hit the index,php file in the domain root.
exm.
api.xyz.com, api.xyz.com/register, api.xyz.com/login
all this request must have to go to index.php
I am facing this error on ipage web host.
Please suggest if anything wrong the host too.
Try this rule:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php/$1 [L]

Categories