Htaccess for subdomain using Codeigniter - .htaccess

Can you help me with htaccess for sub domain using codeigniter.
In my localhost I have this htaccess that is working.
RewriteEngine On
RewriteBase /foldername/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Now if I move my files in my subdomain.sample.com, What should I write in my htaccess ?

In Config.php
# Localhost
$config['base_url'] = 'http://localhost/Appsite/website/';
# Live
$config['base_url'] = 'http://www.sample.com/'; // if secured site use https
# Subdomain
$config['base_url'] = 'http://subdomain.sample.com/';// if secured site use https
To accessing URL
click here
To access image
<img src="<?php echo base_url('assets/images/images.PNG');?>”>
To access css
<link href="<?php echo base_url('assets/css/style.css');?>" rel="stylesheet" />
To access js
<script src="<?php echo base_url('assets/js/some_js.js');?>"></script>

Related

Htaccess doesn´t work - nice url

Hi guys i have problem with a htaccess.
I want from this URL domain.com/index?article=28&title=velky-biel-karlova-ves
(it doesn´t have index.php because i hide .php extension with htaccess.
I wanna have this URL domain.com/clanok/28/velky-biel-karlova-ves
I used this code
My htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^clanok/([\d]+)/([\w-]+)/?$ index.php?article=$1&title=$2 [NC,L]
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
My index.php file:
<a href="index.php?article=<?php echo urlencode($row['id']); ?>&title=<?php echo createSlug($row['title']); ?>" title="">
It doesn´t work.
Thx for help.
Try it like this you still have to mention index.php your php hide rule is different from this,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^clanok/([\d]+)/([\w-]+)/?$ index.php?article=$1&title=$2 [NC,L]
Please ensure this rule is not conflicting with your existing rules.

I can't integrate bootstrap templates in codeigniter

I'm trying to use a Bootstrap template for my project in CodeIgniter but I'm having trouble. I'm following a tutorial and he put this content in .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|fonts|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
But I have my .htaccess file with this content:
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and
leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /ci_introo/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
How can I solve this?
You need to autoload the url helper in config file.
Goto application/config/autoload.php
find for this $autoload['helper'] = array();
and change it to this.
$autoload['helper'] = array('url');
You don't need .htaccess for that.
All you want to do is add url in your autoload.php
and Place this in your head.php
application/views/head.php
<html>
<head>
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/bootstrap.min.css" />
//place all css u need
</head>
Controller code :
$this->load->view('header', $data);

CodeIgniter issues

1) I wanted to get rid of the bootstrap (index.php) name in the URL. I've been in YouTube searching and downloading lots of videos related to this, but none of them worked. This is the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !=f
RewriteCond %{REQUEST_FILENAME} !=d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
I tried everything I could get on the Internet.
2) I couldn't load the files in the public folder where I store my JavaScript, CSS and image files. Path: codeigniter/application/.
What I tried:
<link rel="stylesheet" href="<?=base_URL() ?>public/css/default.css />
And the same for JavaScript files.
3) Routing problems(confusion). My default route us the dashboard controller. But I also wanted to create a login route. So I did this:
$route['login'] = 'login';
But this still routes to the default route when I go to localhost/codeigniter/index.php/login.
Try these .htaccess
# -FrontPage-
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule .* index.php/$0 [PT,L]
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Use this code in .htaccess file and also remove index.php from your config.php file e.g. $config['index_page'] = '';
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

htaccess setting on Codeigniter V2

Hi i'm using Codeigniter V2 and try to rewrite url
So i have done this steps :
I have htaccess file with following code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^asset.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^upload.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
And at config file i change config.php
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO';
This my link website
http://www.beacukaitarakan.com/berita/berita.html
from active url
http://www.beacukaitarakan.com/index.php/berita/berita.html
but with those htaccess file, http://www.beacukaitarakan.com/berita/berita.html will not go to http://www.beacukaitarakan.com/index.php/berita/berita.html but always showing homepage
It can be work if i use QUERY STRING instead of config uri protocol but i have some setting eg. navigation that use this setting
http://www.beacukaitarakan.com/berita/berita.html?p=true&start=1
so i need to use path info rather than QUERY STRING
thanks in advanced
simply copy and paste the below code in the .htacces file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
for more read this http://w3code.in/2015/09/how-to-remove-index-php-file-from-codeigniter-url/

Can't remove index.php from url(IP ADDRESS) in codeigniter framework

I have used below code in htaccess file to remove index.php from url in codeigniter framework
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
It's working fine in local but when in live i am using IP ADDRESS to access my site so it's not removing index.php
You can try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
you should be doing this using routes in code igniter
http://ellislab.com/codeigniter/user-guide/general/routing.html

Resources