Question

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.

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top