CodeIgniter3 .htaccess removing index.php subdomain

Below is the general documentation for editing the .htaccess file to remove index.php from a url

The documentation examples is

example.com/index.php/news/article/my_article
will be the same as
example.com/news/article/my_article

using .htaccess file of:

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

 

https://www.codeigniter.com/userguide3/general/urls.html

However, I tend to use a lot of subdomains of the format

server.com/website1

server.com/website2

To remove index.php from a subdomain is a bit different, you need to add an additional line to .htaccess

RewriteBase /website1/

or

RewriteBase /website2/

The .htaccess file should be:

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

Another interesting Codeigniter Project I found last weekend was

https://github.com/kenjis/codeigniter-composer-installer

I was having some issues with the controller not finding the libraries i put in the third_part folder.  I had the include path correct to the library and it worked on my localhost but wouldn’t work on the server.  I couldn’t figure out the issue and instead used the above project and that worked with no issues on localhost and the server.

This entry was posted in Coding, Web and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s