【问题标题】:codeigniter .htaccess in amazon ec2 removal of index.php not working亚马逊 ec2 中的 codeigniter .htaccess 删除 index.php 不起作用
【发布时间】:2023-03-10 20:20:01
【问题描述】:

亚马逊 ec2 中的 codeigniter .htaccess 删除 index.php 不起作用

代码

RewriteEngine on
RewriteBase http://ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

配置文件

$config['base_url'] = 'http://ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/';

【问题讨论】:

    标签: php codeigniter amazon-ec2


    【解决方案1】:
    (if you use ubuntu)
    Activate the mod_rewrite module with
    
         sudo a2enmod rewrite
    
    and restart the apache
    
         sudo service apache2 restart
    
    To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with
    
         sudo nano /etc/apache2/sites-available/000-default.conf
    
    Search for “DocumentRoot /var/www/html” and add the following lines directly below:
    
        <Directory "/var/www/html">
            AllowOverride All
        </Directory>
    
    Save and exit the nano editor via CTRL-X, “y” and ENTER.
    
    Restart the server again:
    
         sudo service apache2 restart
    

    【讨论】:

    • 我的问题是启用 `sudo a2enmod rewrite' 谢谢 :)
    【解决方案2】:

    只有您可以对所有已部署的应用程序使用“AllowOverride All”规则;写在 /etc/httpd/conf/httpd.conf :

     <Directory "/var/www/html">
         Options Indexes FollowSymLinks
         AllowOverride All 
         Order allow,deny
         Allow from all
     </Directory>
    

    【讨论】:

      【解决方案3】:

      贾斯汀是正确的!

      您也可以对您的项目使用“AllowOverride All”规则;在 /etc/httpd/conf/httpd.conf 中这样写:

      <Directory "/var/www/your_website">
          AllowOverride All
      </Directory>
      

      【讨论】:

        【解决方案4】:

        您可以像这样更改您的 .htaccess

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule .* index.php/$0 [PT,L]
        

        并更改 /etc/httpd/conf/httpd.conf 上“AllowOverride None”的值(如果您使用 AMI Linux)

        进入“AllowOverride All

        之后重启你的 apache 使用如下命令:

        sudo service httpd restart
        

        它在我的 aws ec2 上运行并经过测试。

        【讨论】:

        • 你只需要替换这个下的那个字符串
        • 还有其他人在为此苦苦挣扎吗?在这一点上,我一定已经尝试了 20 种不同的解决方案,但在 ec2 上没有一个对我有用。
        • 我有同样的问题,但这个解决方案适合我。谢谢
        猜你喜欢
        • 2013-09-22
        • 1970-01-01
        • 1970-01-01
        • 2012-02-28
        • 1970-01-01
        • 2013-11-24
        • 1970-01-01
        • 1970-01-01
        • 2014-08-12
        相关资源
        最近更新 更多