Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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 that perhaps it didn't get copied to EC2 instance but I don't think this is the problem because when I copy the project I can see the htaccess file in my editor. 

Is there something enabling mod rewrite in EC2 Linux instance? If there is, I didn't do it or it enables mod rewrite as default?

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php/$1 [L]

1 Answer

0 votes
by (44.4k points)

If you are running Amazon EC2 Linux, you are most likely running httpd rather than Apache. The file is therefore in /etc/httpd/conf/httpd.conf

  • You have to change the file as the root user. (from ssh access) Do this: sudo vim /etc/httpd/conf/httpd.conf
  • DocumentRoot "/var/www/html" was listed in two places for me. I had to change the next AllowOverride None to AllowOverride All in those 2 places.
  • Restart apache. I restarted my whole ec2 instance (i have apache configured to begin automatically) although just restarting apache will work. But I see the change is working.

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
asked Jul 8, 2019 in AWS by yuvraj (19.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers

500 comments

108k users

Browse Categories

...