alias别名的.htaccess配置

当在apache2中使用别名时,配置.htaccess会遇到404错误。
比如以下的alias配置:

 

Alias /htdocs /home/faund/yiidev/htdocs/wwwroot/
<Directory /home/faund/yiidev/htdocs/wwwroot/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>

在/home/faund/yiidev/htdocs/wwwroot/下创建.htaccess内容如下:

 

<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on

# Don't perform redirects for files and directories that exist:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For everything else, redirect to index.php:
RewriteRule ^(.*)$ index.php/$1
</ifModule>

结果会出现404错误。

Not Found

The requested URL /home/faund/yiidev/htdocs/wwwroot/index.php/site/login was not found on this server.

此时需要RewriteBase, 后面跟上Alias的web路径,如下面粗体部分:
 

 

<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
RewriteBase /htdocs

# Don't perform redirects for files and directories that exist:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For everything else, redirect to index.php:
RewriteRule ^(.*)$ index.php/$1
</ifModule>
 

如果此时仍旧出现错误,可以到apache的log中查看原因。如果出现402禁止访问的错误,可以在error_log中查看到这样的错误:

 

[Sat Apr 12 19:05:37.417862 2014] [rewrite:error] [pid 12639] [client ::1:53474] AH00670: Options FollowSymLinks and SymLinksIfOwn
erMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictio
ns : /home/faund/yiidev/webapp/larry_book/public_html/site, referer: http://localhost/yiidev/webapp/larry_book/public_html/
[Sat Apr 12 19:05:37.424453 2014] [mpm_prefork:notice] [pid 12620] AH00163: Apache/2.4.6 (Linux/SUSE) OpenSSL/1.0.1e PHP/5.4.20 co
nfigured -- resuming normal operations

这果需要在.htaccess文件中增加“Options +FollowSymlinks”

 

Options +FollowSymlinks
<ifModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#RewriteBase /yiidev

RewriteRule ^(.*)$ /yiidev/webapp/larry_book/public_html/index.php/$1
</ifModule>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值