Apache 的别名指令未按预期工作



我正在尝试将我的门户与我的网站集成。

我的网站 :

http://example.com

和我的门户:

http://portal.com

现在我想从以下位置查看我的门户:

http://example.com/portal

我的核心 apache 配置文件的一部分(启用站点/网站):

<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>

正如你所看到的,我的门户功能在CodeIgniter之上;因此-

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

我的核心 apache 配置文件的一部分(启用站点/门户):

<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>

现在真正的问题是当我打开 http://example.com/portal 浏览器正在DocumentRoot而不是Alias中查找图像时。

例如,对于来自门户的图像,

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

阿帕奇错误日志说 -

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

我不想对我的代码进行更改。我只想让这个东西从 apache 配置文件本身工作。请帮我做到这一点。

RewriteBase /portal要求网址应以 /portal 开头。所以:

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

不会被击中。

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

将尝试从DocumentRoot搜索文件。

更新1

因为有RewriteBase /portalexample.com/portal/images会命中重写规则,但example.com/images不会,所以:

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

应该是:

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

更新2

这是@Hussain坦博利本人给出的答案,并说:

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

/images/Invoice.png将重写为/portal/images/Invoice.png

最新更新