0

I have looked on a few Stack Overflow questions for removing index.php from sub domain url please don't mark as duplicate.

Stack Overflow I have Read And Tried.

CodeIgniter in subdomain folder, removing the index.php from address

remove index.php of codeigniter subdomains

Removing index.php and handling subdomains of two Codeigniter sites, when one within the other

But non seem to work I am using WAMP and Codeigniter 3 and have MOD Rewrite enabled. Also I use virtual host.

Question: What is the best suitable htacces for sub domain so that I can have the index.php remove?

Page Error:

codeigniter 500 internal server error

My Folder Structure is

www / 
www / codeigniter / cms-1 <-- This is main project
www / codeigniter / cms-1 / application

www / codeigniter / cms-1 / cms-2 <-- This is sub domain 
www / codeigniter / cms-1 / cms-2 / index.php
www / codeigniter / cms-1 / cms-2 / .htaccess

www / codeigniter / cms-1 / image / 
www / codeigniter / cms-1 / system 
www / codeigniter / cms-1 / .htaccess
www / codeigniter / cms-1 / index.php

When I have URL on WAMP like below does not work.

http://www.cms-2.cms-1.com/information/information/3

But when I have index.php works.

http://www.cms-2.cms-1.com/index.php/information/information/3

I have removed on the application > config > config.php

$config['index_page'] = '';

This .htaccess below is on Main directory and works fine for main domain.

Options +FollowSymLinks

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files

<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
    Order deny,allow
    Deny from all
</FilesMatch>

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

2 Answers 2

3

Use this:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>
Sign up to request clarification or add additional context in comments.

4 Comments

No luck goes Internal Server Error
Updated check this now
Thank you for your help I found out what was wrong. + 1
I used your htacces in the main directory now and just have RewriteBase / working fine now. It works for both main and sub domain now.
1

Replace your base_url

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"){$ssl_set = "s";} else{$ssl_set = "";}
$config['base_url'] = 'http'.$ssl_set.'://'.$_SERVER['HTTP_HOST'];

In .htaccess

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

For more read this http://w3code.in/2015/10/how-to-make-multiple-websitesubdomain-of-your-main-site-in-codeigniter-with-same-code-and-database-dynamically/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.