Integrating WordPress, Codeigniter & .htaccess

I have a site that uses wordpress for the frontend & a Codeigniter app for a ‘webshop’ backend. The WordPress structure isn’t in the root, rather it is in the /wp directory.

I require some .htaccess rules that rewrite as follows:
I am trying to do the following –

Read More
  1. if users goes to www.company.com then it does the rewrite rule for the wp (wordpress) folder
  2. if users goes to admin.company.com then it does the rewrite rule to the index.php (for the Codeigniter app)
  3. The final bit is required for the mod_rewrite for wordpress URLS.

The problem I have is that I cannot get both rule 1 and rule 2 working because of RewriteBase rule used – can anyone suggest how to get to use RewriteBase per rule (eg more than once) or similar command to do this?

RewriteCond %{HTTP_HOST} ^(www.)?company.com$
RewriteRule ^(/)?$ wp [L]

RewriteCond %{HTTP_HOST} ^admin.company.com$
RewriteRule index.php [L]

RewriteBase /wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]

RewriteRule ^(.*)$ /index.php?$1 [L]

Related posts

Leave a Reply

1 comment

  1. If you have the codeigniter index file in your root, then you can probably leave the .htaccess file alone and just use the routes file in your codeigniter app.

    $subdomain_arr = explode('.', $_SERVER['HTTP_HOST'], 2); //creates the various parts  
    $subdomain_name = $subdomain_arr[0]; //assigns the first par
    
    if ($subdomain_name == 'admin')) {
        $route['uristring'] = "controller/method";
    } elseif($subdomain_name == 'www')) {
        $route['uristring'] = "controller/method"; // in this method, just do a redirect to your /wp folder.
    }