I have a server from amazon's ec2 service running on Linux Ubuntu ( Ubuntu Server 13.04 64 bit) and I have installed apache, php, and mysql. I have added a .htaccess file in my document root (ie /var/www/).
Here is the code in .htaccess file as follows:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
If I remove .php from url like "index1" instead of "index1.php", it returns 404 browser error. It works properly in my previous server.
I have .htaccess enabled in server. I did it using command "sudo vim /etc/apache2/sites-available/default" and changed "AllowOverride None" to "AllowOverride All".
I have also checked .htaccess working by passing invalid value in htaccess file and it returns "Internal server error - 500" in browser.
Here is the link of my server information : http://54.200.58.45/mytest.php
Any help in this regard will be highly appreciated.
This is wat worked for me on a fresh EC2 instance with Ubuntu 13.10:
<Directory "/var/www"> AllowOverride All </Directory>
This happens because the rewrite module doesn't come enabled by default for security reasons.
Create a new file called rewrite.conf
in /etc/apache2/mods-enabled
in the file put this line LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
Now reload server sudo service apache2 restart
This worked for me and hopefully for you, but I don't advice this for production servers. This is information for regular Ubuntu users not for a live server.
The problem is by default in apache installed on Ubuntu doesn't have .htaccess enabled so first you have to manually enable it in a config file and restart apache.
Here are the steps.
1) Login to your EC2 instance with SSH.
ssh -i "Yourkey.pem" ubuntu@yourpublicip
2) Enable Mode Rewrite, this is just incase if it's not enabled.
sudo a2enmod rewrite
3) 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 is applied to your sites in /var/www/html folder.
4) Open this file for editing.
sudo nano 000-default.conf
5) 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
6) Save the file and restart the apache.
sudo service apache2 restart
that's it and now your .htaccess file will work
您需要先检查是否启用了 mod rewrite 模块。
Tried everything and nothing worked...
2 hours later.. Finally fixed it.
So first the things to rule out.
Make sure that you have made the changes in /etc/apache2/apache2.conf and in / etc/apache2/sites-enabled/000-default.conf that everyone is talking about... (AllowOverride All and AccessFileName .htaccess must not be commented out)
Make sure that the Directory /var/www/html is pointing to the right folder. Some times it has /html and some times it's just /var/www (however it must not end in / i think, but that might not matter.)
Success :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.