3

I am trying to integrate my portal with my website.

My website :

http://example.com

and My portal :

http://portal.com

Now I want to see my portal from :

http://example.com/portal

Part of my core apache config file (sites-enabled/website):

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName example.com
    DocumentRoot /home/example/WebSite2.0/WebContent
    DirectoryIndex index.php index.html

    <Directory /home/example/WebSite2.0/WebContent>
            Options  +IncludesNOEXEC
            AllowOverride None
            Order allow,deny
            allow from all
            XBitHack On
            AddType text/html .html
            AddHandler server-parsed .html   
    </Directory>

    Alias /portal /home/example/portal/CodeIgniter_2.1.0
    <Directory /home/example/portal/CodeIgniter_2.1.0>
            DirectoryIndex "index.php"
            allow from all
            Options +Indexes
            #Options  FollowSymLinks MultiViews
            Order allow,deny

            RewriteEngine On
            RewriteBase /portal
            #RewriteRule ^test\.html$ test.php 

            RewriteCond $1 !^(index\.php|css|images|robots\.txt)
            RewriteRule ^(.*)$ index.php/$1 [L]

            RewriteCond $1 ^(css|images|js)
            RewriteRule ^(.*)$ $1

    </Directory>
</VirtualHost>

As you see my portal functions on top of CodeIgniter; Hence -

 RewriteCond $1 !^(index\.php|css|images|robots\.txt)
 RewriteRule ^(.*)$ index.php/$1 [L]

Part of my core apache config file (sites-enabled/portal) :

<VirtualHost *:443>
    ServerAdmin webmaster@localhost
    ServerName portal.com
    ServerAlias www.portal.com
    DocumentRoot /home/example/portal/CodeIgniter_2.1.0
    DirectoryIndex "index.php"
    SSLEngine On
    SSLCertificateFile "ssl/portal.com.crt"
    SSLCertificateKeyFile "ssl/portal.com.key"
    <Directory /home/example/portal/CodeIgniter_2.1.0>
            Options  FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
            Header unset Server
            ServerSignature Off
    </Directory>
</VirtualHost>

Now the real problem is when I open http://example.com/portal the browser is looking for the images in the DocumentRoot and not in Alias.

e.g. for image from portal,

<img src="/images/example.png" style="margin-left:30px;height:50px;">

apache error log says -

File does not exist: /home/example/WebSite2.0/WebContent/images/example.png

I would hate to make changes to my code. I just want to get this thing working from the apache config file itself. Please help me do this.

Hussain
  • 5,057
  • 6
  • 45
  • 71

1 Answers1

1

RewriteBase /portal require that the url should begin with /portal. So:

RewriteCond $1 !^(index\.php|css|images|robots\.txt)

will not be hit.

<img src="/images/example.png" style="margin-left:30px;height:50px;">

will try to search file from DocumentRoot.

update1

For there is RewriteBase /portal, example.com/portal/images will hit the Rewrite rule, but example.com/images will not, so:

 <img src="/images/example.png" style="margin-left:30px;height:50px;">

should be:

 <img src="/portal/images/example.png" style="margin-left:30px;height:50px;">

update2

It is the answer given by @Hussain Tamboli himself, with:

RewriteRule /(images|js|css)/(.+)\.(.+)$ /portal/$1/$2.$3 [PT].

/images/Invoice.png will rewrite to /portal/images/Invoice.png

srain
  • 8,944
  • 6
  • 30
  • 42
  • what is the full path of `example.png`? – srain Sep 10 '13 at 07:10
  • Here - `/home/example/portal/CodeIgniter_2.1.0/images/example.png` – Hussain Sep 10 '13 at 07:11
  • You can use `http://portal.com/images/example.png` to access this image, now you want to use `http://example.com/portal/images/example.png` to access this file, right? – srain Sep 10 '13 at 07:13
  • Replying to your answer. You said "will not hit.". But the rewrite condition below that works fine. To verify it, I did `RewriteCond $1 ^(css|images|js) RewriteRule ^(.*)$ css` and you see http://example.com/portal/images or js redirects me to http://example.com/portal/css – Hussain Sep 10 '13 at 07:58
  • Yes, `example.com/portal/images` will hit, but `example.com/images` will not. – srain Sep 10 '13 at 10:14
  • I think. I am gonna have to do it without `RewriteBase`; Write a separate rule to match /images/anything and then replace it by /portal/images/anything. Can you help me write those rules? – Hussain Sep 10 '13 at 10:28
  • Do you mean map `example.com/images/anything` to `/home/example/portal/CodeIgniter_2.1.0/images/anything` ? – srain Sep 10 '13 at 10:44
  • No. Like in the update 1, you have mentioned. just add `/portal` to `/images/example.png`. – Hussain Sep 10 '13 at 10:56
  • Your current config can map `example.com/portal/images/example.png` to `/home/example/portal/CodeIgniter_2.1.0/images/example.png`. Have you tried it? – srain Sep 10 '13 at 10:58
  • yes. but when I hit example.com/portal, CI's index.php redirects me to example.portal/users/login?redirectURL=/? where the images don't appear – Hussain Sep 10 '13 at 11:26
  • `example.com/portal` map to `/home/example/portal/CodeIgniter_2.1.0/index.php`, I think this file will check login, if your did not sign in, will redirect to `example.portal/users/login` – srain Sep 10 '13 at 12:00
  • This is what I am talking about - `RewriteRule /(images|js|css)/(.+)\.(.+)$ /portal/$1/$2.$3 [PT]`. To verify this, I checked the rewrite log. It says `applying pattern '/(images|js|css)/(.+)\.(.+)$' to uri '/images/Invoice.png'` and `rewrite '/images/Invoice.png' -> '/portal/images/Invoice.png'`. You can add this to the answer – Hussain Sep 12 '13 at 10:25
  • Yes, that is right. In this rewriterule, `` will output the image you want. – srain Sep 12 '13 at 13:23