Category Archives: base-url

Codeigniter still shows index.php after forcing https

Just launched my site with an SSL certificate. When I go to the https site it works perfectly. However if I force just http, even after configuring htaccess, it forwards me to the https site, but it adds index.php?/ to the end of the url. For example if I go to it redirects to Of course the site works fine, its just a bit of an eyesore in the url field.

base_url variable is as shown:

$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['PHP_SELF']).'/');

My .htaccess looks like this:

RewriteEngine on
RewriteCond $1 !^(index\.php?|_assets|robots\.txt|sitemap\.xml|favicon\.ico?)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I added the last 2 lines after researching how to force https when a visitor visits the site with http.

What am I missing? htaccess is not my strong suit. It's shared access otherwise I'd edit my httpd.conf

Codeigniter still shows index.php after forcing https

Just launched my site with an SSL certificate. When I go to the https site it works perfectly. However if I force just http, even after configuring htaccess, it forwards me to the https site, but it adds index.php?/ to the end of the url. For example if I go to it redirects to Of course the site works fine, its just a bit of an eyesore in the url field.

base_url variable is as shown:

$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['PHP_SELF']).'/');

My .htaccess looks like this:

RewriteEngine on
RewriteCond $1 !^(index\.php?|_assets|robots\.txt|sitemap\.xml|favicon\.ico?)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I added the last 2 lines after researching how to force https when a visitor visits the site with http.

What am I missing? htaccess is not my strong suit. It's shared access otherwise I'd edit my httpd.conf

EDIT: Updated htaccess looks like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This technically works, but for some reason when I access the site using http it redirects to the https version but concatenates another copy of my URI to the end. For example if I go to it redirects to

How to define base URL in .htaccess

I am redirecting<a number>&title=<the page title>

to<a number>/<the-page-title>

Now I want to move the website to a sub folder so the redirection will be

https://www,<a number>&title=<the page title>

to<a number>/<the-page-title>

I am using the below .htaccess code

RewriteEngine On

RewriteCond %{THE_REQUEST} /inter\.php\?pid=([^&\s]+)&title=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,NE,L]

RewriteRule ^(\S+)\s+(.*)$ $1-$2 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^(\S+)$ /$1 [NE,R=302,L]

RewriteRule ^([^/]+)/([^/]+)/?$ inter.php?pid=$1&title=$2 [L,QSA]

Please Suggest. thanks!

Having problems with AngularJS html5Mode

I am currently having trouble with AngularJS html5Mode. I am working on a blog site that is hosted on my localhost WAMP server. I have a base URL defined in my index.html file and I have html5Mode set to true in the config section in my app.js file and I also have a .htaccess file in my directory.

This is what my url looks like without html5 mode enabled. http://localhost/Blog/index.html/#posts

If I load my site like this: localhost/Blog/ or localhost/Blog/index.html it will redirct to localhost/Blog/posts which is what I want.

But if I try to type this url manually or refresh the page it goes to localhost/dashboard and If I click on one of the other links it will go to localhost/nameOfLink

I am not 100% sure but I think the problem could be in the .htaccess file

This is my index.html file

<!DOCTYPE html>
<html lang="en" ng-app="blog" class="no-js" ng-cloak>
    <base href="/Blog/">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="theme-color" content="#29B6F6">
    <meta name="msapplication-navbutton-color" content="#29B6F6">
    <meta name="apple-mobile-web-app-status-bar-style" content="#29B6F6">
    <title>Phone reviews</title>
    <link rel="stylesheet" href="">
    <link rel='stylesheet' id='primary-font-css'  href=',400,500,700' type='text/css' media='all' />
    <link rel="stylesheet" href="">
    <link href="main.css" rel="stylesheet">
<body ng-controller="MainCtrl">

        <nav class="navbar navbar-inverse navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#nav0">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    <a href="login.html" class="navbar-brand">Phone Reviews</a>
                <div class="collapse navbar-collapse" id="nav0" ng-controller="NavCtrl">
                    <ul class="nav navbar-nav navbar-right">
                        <li ng-click="scroll()" ng-class="{ active: isActive('/posts')}"><a href="#/posts">Home</a></li>
                        <li ng-click="scroll()" ng-class="{ active: isActive('/contact')}"><a href="#/contact">Contact Us</a></li>
                        <li ng-click="scroll()" ng-class="{ active: isActive('/registration')}"><a href="#/registration">Register</a></li>
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="">My Account <i class="fa fa-caret-down"></i></a>
                            <ul class="dropdown-menu" ng-init="userInit(<?php echo $_SESSION['name'] $_SESSION['role']; ?>)">
                                <li><a href="#">{{user}}</a></li>
                                <li><a href="#">Account</a></li>
                                <li><a href="#">Favourites</a></li> 
                                <li><a href="#">Settings</a></li> 
                                <li><a href="#">Logout</a></li> 
                </div> <!-- /.navbar-collapse -->
            </div> <!-- /.container -->

        <header class="header">
            <h1>Phone Reviews</h1>

        <div class="alert alert-dismissible alert-success">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <p>You have successfully registered! Go to your email to confirm account.</p>

        <div class="social-icons">
                <li><a href="#" class="icon facebook"><i class="fa fa-facebook"></i></a></li>
                <li><a href="#" class="icon instagram"><i class="fa fa-instagram"></i></a></li>
                <li><a href="#" class="icon youtube"><i class="fa fa-youtube"></i></a></li>
                <li><a href="#" class="icon twitter"><i class="fa fa-twitter"></i></a></li>
                <li><a href="#" class="icon pinterest"><i class="fa fa-pinterest"></i></a></li>

        <div class="container-fluid" id="wrapper">
            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12 content"><div ng-view></div></div>
            <div ng-include="'includes/sidebar.html'"></div>

        <div ng-include="'includes/footer.html'"></div>

<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script async defer data-pin-hover="true" data-pin-tall="true" data-pin-round="true" data-pin-save="false" src="//"></script>
<script src="ui-bootstrap.js"></script>
<script src="page.js"></script>
<script src="app.js"></script>

This is my app.js file

var app = angular.module('blog', ['ngRoute', 'ngSanitize', 'ui.bootstrap.tpls', 'angularUtils.directives.dirPagination'])

.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {

      when('/posts', { templateUrl: 'includes/main.html', controller: 'MainCtrl' }).
      when('/posts/:postUrl', { templateUrl: 'includes/post.html', controller: 'PostCtrl' }).
      when('/contact', { templateUrl: 'includes/contact.html', controller: 'ContactCtrl' }).
      when('/registration', { templateUrl: 'includes/register.html', controller: 'RegistrationCtrl'}).
      otherwise({redirectTo: '/posts'});

This is my .htaccess file

RewriteEngine on

# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]

BASE_URL – GODADY – system codeigniter

I would need some help, I have go-dady hosting and sub-domain. I also have simple HTML website that is included in codeigniter system. The problem is that main page works (, but all sub-pages doesn't work, i get error:

No input file specified. 

My base url in set:

$config['base_url'] = '';

My current .htaccess is:

<IfModule authz_core_module>
Require all denied
<IfModule !authz_core_module>
    Deny from all

# Mod Rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I found that I should add #Mod Rewrite on godady hosting to work correctly, but not in my case.

What should I change to make codigniter work on godady hosting ? I have no problems on other hosting's.

What is the correct way to run ZF application under url sub-folder under Apache?

This is probably a common question but I couldn't find an answer to it.

I have a PHP application using Zend Framework. Say we I run the application under my-app host and the source files are located under /my-path/my-app in local file system. Below is the Apache vhost config:

<VirtualHost *:80>
ServerName my-app
DocumentRoot "/my-path/my-app/public"
<Directory "/my-path/my-app/public">
    AllowOverride All
    Require all granted

The .htaccess file in public directory contains following rewrite rules:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

So far, all standard for ZF applications.

Now, I need to run this application under an url sub-folder (for example foo), i.e. under http://my-app/foo/ instead of http://my-app/.

What do I need to change to make this work? What is the best practice?

Assume that generating URLs with the base-url from the application is not a problem. And also assume that the application will rewrite all URLs including the links for css/js sources for the application.


How to get baseUrl in Yii2 advanced app after Url rewrite

I have used Yii2 advanced application. i rewrite url in frontend and backend. After rewrite Frontend url is


And For Backend


Now i want to get base url like


But i don't get it properly

I have tried following ways,

echo Yii::getAlias('@web') // ans= /Working-copy/mySite/admin
echo Yii::getAlias('@backend') // ans= /var/www/Working-copy/mySite/backend 
echo Yii::getAlias('@webroot') // ans= /var/www/Working-copy/mySite/backend
echo Yii::$app->request->BaseUrl // ans= /Working-copy/mySite/admin
echo Yii::$app->getBasePath(false) // ans= /var/www/Working-copy/mySite/backend
echo Yii::$app->homeUrl // ans = /Working-copy/mySite/admin/

In some url i get /var/www/ and in some url get /admin/.

i only want my project name. any solution please?

TYPO3 links from non-https to http

Goal: Every non-https link has to become https. Always.

Achieved by now:

  • Changed base-url to https
  • Each link is https IF I'm on non-http

My issue is stated at my second achievement. For some reasons the links targets to https if I am on a non-https page, otherwise to http. I know I could implement a work-around using .htaccess but this isn't the clean way and I want to implement it in a clean way.

What I've done to fix it:

I know one can force the protocoll for a single typo3 page and I can update all pages via database but in this case it's not possible as it's a multitree presentation and not every tree have to use https.

I also googled and read about config.baseUrl but I've changed that before I even googled.

On the presentation "Enforce https" having key "https" is installed but I can't find it in the Ext. Repository.

Further stuff:

I guess the issue is not caused by .htaccess but in any case: This in my .htaccess file

RewriteCond %{HTTP_HOST} ^mydomain\.de$
RewriteRule (.*)$1 [R=301,L] 

Any help is appreciated.

how to change live .htaccess for locahost? [on hold]

I configured a live site into my localhost folder which name is "". But i try to run this folder its give me error :

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.
Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80

when i rename my .htaccess file then my home page is run successfully but other pages still gives me error like above error.

.htaccess file code:

# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php

# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
RewriteEngine On

# redirect non-www to www http/https
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#RewriteCond %{HTTPS} on
#RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

# redirect www to non-www http/https
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#RewriteCond %{HTTPS} on
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteRule ^home.html$ index.php?parentid=no [L]
RewriteRule ^login.html$ main.php [L]
RewriteRule ^singup.html$ register.php?parentid=1015 [L]
RewriteRule ^add-testimonial.html$ testimonial.php?addtestimonial=true [L]

#System Default Navigation
RewriteRule ^home.html$ index.php?parentid=home.html [L]
RewriteRule ^imei/productsandservices.html$ productsandservices.php?currentpage=productsservices&action=imei&parentid=imei/productsandservices.html [L]
RewriteRule ^file/productsandservices.html$ productsandservices.php?currentpage=productsservices&action=file&parentid=imei/productsandservices.html [L]
RewriteRule ^server/productsandservices.html$ productsandservices.php?currentpage=productsservices&action=server&parentid=imei/productsandservices.html [L]
RewriteRule ^search/productsandservices.html$ productsandservices.php?currentpage=productsservices&action=search&parentid=imei/productsandservices.html [L]
RewriteRule ^testimonials.html$ testimonial.php?parentid=testimonials.html [L]
RewriteRule ^knowledgebase.html$ knowledgebase.php?parentid=knowledgebase.html [L]
RewriteRule ^contactus.html$ contact.php?parentid=contactus.html [L]
RewriteRule ^blog.html$ blog.php?parentid=blog.html [L]
RewriteRule ^trackorder.html$ trackservice.php?parentid=trackorder.html [L]
RewriteRule ^cart.html$ cart.php?parentid=cart.html [L]
RewriteRule ^hotdeal.html$ hotdeal.php?parentid=hotdeal.html [L]
RewriteRule ^downloads.html$ downloadfile.php?parentid=downloads.html [L]
RewriteRule ^submitticket.html$ support.php?parentid=submitticket.html [L]
RewriteRule ^main.html$ main.php?parentid=main.html [L]
RewriteRule ^placeorder.html$ placeorder.php?parentid=placeorder.html [L]
RewriteRule ^imei/placeorder.html$ placeorder.php?parentid=placeorder.html [L]
RewriteRule ^file/placeorder.html$ placeorder.php?action=file&parentid=placeorder.html [L]
RewriteRule ^server/placeorder.html$ placeorder.php?action=server&parentid=placeorder.html [L]
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/orders.html$ orders.php?action=$1&status=$2&parentid=imei/all/orders.html [L]
RewriteRule ^affiliate.html$ settings.php?action=affiliate [L]

#Required for cart
RewriteRule ^([0-9]+)/([a-zA-Z0-9_-]+)-bestdeal.html$ index.php?action=bestdeal&prod=$1 [L,NC]
RewriteRule ^([0-9]+)/([a-z0-9_-]+)$ cart.php?group=$1&service=product&parentid=1008 [L,NC]
RewriteRule ^([0-9]+)/([0-9]+)/([a-z0-9_-]+)$ cart.php?group=$1&item=$2&service=product&parentid=1008 [L,NC]
RewriteRule ^([0-9]+)/feature/([a-z0-9_-]+)/([a-z0-9_-]+).html$ cart.php?group=$1&fid=$2&service=product&parentid=1008 [L,NC]
RewriteRule ^imei/([0-9]+)/([a-z0-9_-]+)$ cart.php?group=$1&service=imei&parentid=1008 [L,NC]
RewriteRule ^imei/([0-9]+)/([0-9]+)/([a-z0-9_-]+)$ cart.php?group=$1&item=$2&service=imei&parentid=1008 [L,NC]
RewriteRule ^server/([0-9]+)/([a-z0-9_-]+)$ cart.php?group=$1&service=server&parentid=1008 [L,NC]
RewriteRule ^server/([0-9]+)/([0-9]+)/([a-z0-9_-]+)$ cart.php?group=$1&item=$2&service=server&parentid=1008 [L,NC]

#Product and services details page
RewriteRule ^product-and-services/parent/([a-z0-9_-]+)/([a-z0-9_-]+)/([a-z0-9_-]+).html$ productsandservices.php?action=getdetail&service=$2&parentid=1006 [L,NC]
RewriteRule ^product-and-services/([a-z0-9_-]+)/([a-z0-9_-]+).html$ productsandservices.php?action=getdetail&service=$1 [L,NC]

RewriteRule ^knowledgebase/([a-z0-9_-]+)/([a-z0-9_-]+)$ knowledgebase.php?currentpage=knowledgebase&category=$1 [L,NC]
RewriteRule ^knowledgebase/([a-z0-9_-]+)/([a-z0-9_-]+).html$ knowledgebase.php?currentpage=knowledgebase&artical=$1 [L,NC]

RewriteRule ^blog/([a-z0-9_-]+)$ blog.php?postid=$1 [L,NC]
RewriteRule ^blog/([a-z0-9_-]+)/([a-z0-9_-]+)$ blog.php?category=$1 [L,NC]
RewriteRule ^blog/([a-z0-9_-]+)/([a-z0-9_-]+).html$ blog.php?postid=$1 [L,NC]
RewriteRule ^blog/page-([a-z0-9_-]+)$ blog.php?page=$1 [L,NC]

#Custom pages
RewriteRule ^([A-Za-z0-9_-]+).html?$ cms.php?page=$1&parentid=$1.html [L]

ErrorDocument 401 /error.php?error=401
ErrorDocument 403 /error.php?error=403
ErrorDocument 404 /error.php?error=404
ErrorDocument 500 /error.php?error=500

RewriteRule ^(.+)\.tpl$ /index.php [r=301,nc]
RewriteRule ^(.+)\.txt$ /index.php [r=301,nc]

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"

<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

<ifModule mod_headers.c> 
Header set Connection keep-alive 

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

I tried many things but still got no solution. Please help . Thanks

Code Igniter, Not Found 404 Error

I have a problem with my site. After upgrading to mySQL 5.6, then the host povider did a recompilation of Apache and PHP. apparently they also upgraded the WHM cPanel.

as for now my site can display properly, but when tried to login, it can't find the specific page requested.

The error Message:

The requested URL /main/cek_login was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

error messages from cPanel:

[Mon Dec 22 10:10:58 2014] [error] File does not exist: /home/xxx/public_html/main [Mon Dec 22 10:10:56 2014] [error] File does not exist: /home/xxx/public_html/404.shtml

My analyses so far:

CI version : 2.2
PHP Version :
mySQL version : 5.6.21
cPanel Version 11.46.1 (build 4)

main -> is actually a file called main.php
cek_login -> is a function inside main.php that run verification against record in user table.

the folder structure as follows.


The code as follows

<div class="loginForm">
  <?=($_GET[ 'error'])? "<div class='alert'>$_GET[error]</div>": ""?>
    <form class="form-horizontal" action="<?php echo base_url().'main/cek_login'; ?>" method="POST">

config.php inside application folder
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI'; -> tried AUTO before, but useless. Previously was AUTO

.htaccess in root folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

.htaccess in another folder
deny from all

$route['default_controller'] = "main";
$route['404_override'] = 'not_found';

I tried to see config files as well and tried a lot of tricks before posting this.

my suspicion is on the base_url function or the routing mechanism. I am not sure.

I am NEW to Code Igniter or PHP, also in Server Administration. my strength lies in Database.

Please help on narrowing the root problem.

best regards, Ridwan