【问题标题】:Hiding "index.php" at url in "YII" when using "https" does not work使用“https”时在“YII”中的 url 隐藏“index.php”不起作用
【发布时间】:2013-06-13 00:10:28
【问题描述】:

在这里,我遇到了一个小问题。我有一个用 Yii 框架构建的网站。它使用 http 协议运行没有任何问题(url 中的 index.php 是隐藏的,所有 url 都可以正常工作)。我已经在亚马逊 ec2 服务中托管了这个。我的 .htaccess 文件中有以下几行

Options +FollowSymLinks

IndexIgnore */*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

但是当我使用 https 浏览网站时(注意:我已经全部配置好了),主页正常加载。但其他 url 不起作用,需要添加 /index.php/。我在这里想念什么?

渴望答案。

提前致谢。

【问题讨论】:

  • 您是否在配置文件中将 showScriptName 设置为 false?
  • // 取消注释以下以启用路径格式的 URL 'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'rules'=>array( '/'=>'/view', '//'=>' /', '/'=>'/', ), ),
  • 是的,配置中的 showScriptName 为 false ...
  • 您是否检查过相同的 url 是否适用于 http?您的 .htaccess 看起来不错,应该适用于 http 和 https。
  • 是的,使用 http 隐藏 .index.php 可以正常工作。我也相信在我用 https 测试之前它会起作用。我尝试将“RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]”添加到我的 htaccess 文件中...

标签: .htaccess https yii


【解决方案1】:

要让 mod_rewrite 工作,不仅必须安装 mod_rewrite,而且如果规则“AllowOverride None”,还要检查 Apache 目录配置(在通过 apt-get 安装的 Ubuntu 上是 /etc/apache2/sites-enabled/000-default)存在于您项目的目录配置中。如果是这样,请将其更改为“AllowOverride All”。

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
**AllowOverride All**

mod_rewrite 可以通过从该行删除注释来安装

#LoadModule rewrite_module modules/mod_rewrite.so

【讨论】:

    【解决方案2】:

    经过长时间搜索 .htaccess 配置,主文件配置,在 default-ssl 文件中的 /etc/apache2/sites-enabled 目录中找到了解决方案。 (感谢 Hemc 的回答)

    这就是我所做的。这可能对其他人有所帮助:

    首先移动到 apache 的启用站点的目录

    cd /etc/apache2/sites-enabled
    

    然后打开default-ssl文件

    sudo vi default-ssl 
    

    然后将 AllowOverride None 更改为 AllowOverride All

    实际上这是在我的文件的顶部,它工作正常。即。我的 index.php 被正确隐藏并且 url 工作正常 :)

        <IfModule mod_ssl.c>
        <VirtualHost *:443>
        ServerAdmin webmaster@localhost
    
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
    
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
    

    最后保存退出后,别忘了重启你的apache

     sudo service apache2 restart
    

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-06
      • 1970-01-01
      • 2015-01-26
      • 2011-05-29
      • 1970-01-01
      • 2012-05-19
      • 2015-12-19
      • 2010-11-20
      相关资源
      最近更新 更多