Apache的Alias指令未按预期工作

3

我希望你能帮我将我的门户网站与我的网站进行集成。

我的网站:

http://example.com

并且我的门户网站:
http://portal.com

现在我想从以下位置查看我的门户:
http://example.com/portal

以下是我的核心Apache配置文件部分(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>

如您所见,我的门户网站是在CodeIgniter之上运行的;因此 -

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

以下是我的核心Apache配置文件(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>

现在真正的问题是当我打开http://example.com/portal时,浏览器会在DocumentRoot中寻找图片而不是在Alias中寻找。
例如,对于来自门户网站的图片,
<img src="/images/example.png" style="margin-left:30px;height:50px;">

Apache错误日志显示 -

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

我不想修改我的代码,只希望从Apache配置文件中让这个东西工作起来。请帮助我完成这个任务。


你能在这里粘贴 portal.com 的配置吗? - srain
完成。已将翻译文本添加到问题中。 - Hussain
1个回答

1

RewriteBase /portal 表示url必须以/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 Tamboli本人给出了答案,包括:

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

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


example.png的完整路径是什么? - srain
这里 - /home/example/portal/CodeIgniter_2.1.0/images/example.png - Hussain
是的,example.com/portal/images 可以访问,但 example.com/images 不行。 - srain
不需要。就像您在更新1中提到的那样,只需将“/portal”添加到“/images/example.png”即可。 - Hussain
example.com/portal 映射到 /home/example/portal/CodeIgniter_2.1.0/index.php,我认为这个文件将会检查登录状态,如果您没有登录,将会重定向到 example.portal/users/login - srain
显示剩余8条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接