dongwopu8210 2013-09-10 06:02
浏览 31
已采纳

Apache Alias指令未按预期工作

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.

  • 写回答

1条回答 默认 最新

  • doulin8374 2013-09-10 06:47
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么