htaccess works in localhost but doesn't work in EC2 instance

后端 未结 6 644
情深已故
情深已故 2020-12-14 19:36

My htaccess file works on localhost but doesn\'t work when i deploy it to EC2 instance.

I\'m using Macbook and in finder i cannot see the htaccess file, i thought t

相关标签:
6条回答
  • 2020-12-14 19:48

    By default EC2 doesn't have .htaccess enabled, you must edit your httpd.config to allow for it.

    In /etc/apache/sites-available/default change AllowOverRide = None to AllowOverRide = All.

    0 讨论(0)
  • 2020-12-14 19:57

    I pieced together some info from various posts so I thought I'd put up an answer.

    1. As Paul commented, If you're running Amazon EC2 Linux, you're probably running httpd instead of Apache. The file is therefore in /etc/httpd/conf/httpd.conf
    2. You have to change the file as root user. (from ssh access) Do this: sudo vim /etc/httpd/conf/httpd.conf (How to edit httpd.conf file in AMAZON EC2)
    3. DocumentRoot "/var/www/html" was listed in two places for me. I had to change the subsequent AllowOverride None to AllowOverride All in those two places.
    4. Restart apache. I restarted my whole ec2 instance (i have apache configured to start automatically) although just restarting apache should work. But I see the change is working.

    I was trying to make the same changes in a .htaccess file (removing the index.php from urls in a code igniter application). Hope it helps!

    0 讨论(0)
  • 2020-12-14 20:00

    On Linux enviroment 1 - cd /etc/apache2/sites-available

    2 - sudo nano 000-default.conf

    and paste this code:

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

    This worked on AWS instance.

    0 讨论(0)
  • 2020-12-14 20:02

    There are three steps

    1. Configure apache mod_rewrite,run in terminal. sudo a2enmod rewrite

    2. Add this code in this file after closing VirtualHost tag /etc/apache2/sites-available/000-default.conf

      DocumentRoot /var/www
      Options FollowSymLinks
      AllowOverride All
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all

    3. Restart apache server by command

      sudo service apache2 restart

    0 讨论(0)
  • 2020-12-14 20:08

    Its a three step process

    1. Configure apache mod_rewrite,run in terminal. sudo a2enmod rewrite

    2. add the following code to /etc/apache2/sites-available/default

    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>
    

    3.Restart apache

    /etc/init.d/apache2 restart
    
    0 讨论(0)
  • 2020-12-14 20:11

    When you using the apache2 server

    Go to the following directory.

    cd /etc/apache2/sites-available

    If you use LS command here you will see the following file.

    000-default.conf

    That's the file with default apache configuration which are applied to your sites in /var/www/html folder.

    Open this file for editing.

    sudo nano 000-default.conf

    Add following lines after DocumentRoot /var/www/html line.

    Options FollowSymLinks AllowOverride All Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all
    

    Save the file and restart the apache.

    sudo service apache2 restart

    that's it and now your .htaccess file will work

    0 讨论(0)
提交回复
热议问题