1

I want to serve my main domain from a sub-directory in the doc_root in a shared Apache/PHP server. The application is developed using Codeigniter and all the urls are dynamically created using base_url() function. The problem is, all the urls have the name of the subdirectory as well. I want to remove it but don't know how to do it.

base_url produces urls like http://example.com/v2/public_html/page1. but I want it to produce http://example.com/page1. Both the above urls serve the correct page however.

This is my directory structure:

|-doc_root
   |-v1 
   |-v2
       |-system
       |-application
       |-public_html
         |-.htaccess
       |-.htaccess
   |.htaccess

In my config.php file I have setup $config['base_url'] = "http://example.com/";

.htaccess file in doc_root:

RewriteEngine on
RewriteRule    ^$    v2/public_html/    [L]
RewriteRule    (.*) v2/public_html/$1    [L]

.htaccess in doc_root/v2:

RewriteEngine on
RewriteRule    ^$    public_html/    [L]
RewriteRule    (.*) public_html/$1    [L] 

And the .htaccess in doc_root/v2/public_html:

RewriteEngine on
RewriteBase /v2/public_html
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Please help me to get this resolved.

Johna
  • 1,836
  • 2
  • 18
  • 29
  • what did you mean by 'rewrite base ...'.? – Johna Jul 06 '16 at 02:23
  • RewriteBase http://stackoverflow.com/questions/21347768/what-does-rewritebase-do-and-how-to-use-it Just thought it might be helpful in your subdomains folder. But I see now you already have that. – ArtisticPhoenix Jul 06 '16 at 02:30
  • You'll have to look at how CI is creating the urls and possibly do them another way with like a global php constant for example. The issue is not really with .htaccess but how you write the urls. Otherwise youll have to do like a [R] redirect to change the url in the browser. Which is an additional network hop. See htaccess will make the modified ( incorrected ) urls map correctly to your site. You can do the other way around but its more legwork, for your requests. – ArtisticPhoenix Jul 06 '16 at 02:33
  • I changed the `base_url` helper function to strip the subfolder name, not the correct way though. – Johna Jul 06 '16 at 04:27

0 Answers0