首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache的Alias指令不像预期的那样工作

问Apache的Alias指令不像预期的那样工作
EN

Stack Overflow用户
提问于 2013-09-10 06:02:38
回答 1查看 1.2K关注 0票数 3

我正在尝试把我的门户和我的网站整合起来。

我的网站:

代码语言:javascript
复制
http://example.com

我的门户:

代码语言:javascript
复制
http://portal.com

现在我想看看我的门户网站:

代码语言:javascript
复制
http://example.com/portal

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

代码语言:javascript
复制
<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之上;因此-

代码语言:javascript
复制
 RewriteCond $1 !^(index\.php|css|images|robots\.txt)
 RewriteRule ^(.*)$ index.php/$1 [L]

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

代码语言:javascript
复制
<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中查找图像。

例如门户网站上的图像,

代码语言:javascript
复制
<img src="/images/example.png" style="margin-left:30px;height:50px;">

apache错误日志上写着-

代码语言:javascript
复制
File does not exist: /home/example/WebSite2.0/WebContent/images/example.png

我不想修改我的代码。我只想让这个东西从apache配置文件本身开始工作。请帮我做这个。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-10 06:47:33

RewriteBase /portal要求url以/portal开头。所以:

代码语言:javascript
复制
RewriteCond $1 !^(index\.php|css|images|robots\.txt)

不会被击中。

代码语言:javascript
复制
<img src="/images/example.png" style="margin-left:30px;height:50px;">

将尝试从DocumentRoot搜索文件。

update1

由于有RewriteBase /portal,example.com/portal/images将命中重写规则,但example.com/images不会,因此:

代码语言:javascript
复制
 <img src="/images/example.png" style="margin-left:30px;height:50px;">

应:

代码语言:javascript
复制
 <img src="/portal/images/example.png" style="margin-left:30px;height:50px;">

update2

这是@Hussain Tamboli本人给出的答复:

代码语言:javascript
复制
RewriteRule /(images|js|css)/(.+)\.(.+)$ /portal/$1/$2.$3 [PT].

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18711695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档