I have a server from AWS EC2 service running on Linux ubuntu and I have installed apache, php, and mysql.
I have added a .htaccess
file in my document root /var/www/html
.
I entered this code in it:
ErrorDocument 404 /var/www/html/404.php
and it is still not showing up.
I kept entered this command multiple times: sudo service httpd restart
to restart the server but no changes displayed...
How can I fix this... Did I do something wrong?
Thanks in advance!
If you have tried all of the above, which are all valid and good answers, and your htaccess file is not working or being read change the directive in the
apache2.conf
file. Under Ubuntu the path is/etc/apache2/apache2.conf
Change the
<Directory>
directive pointing to your public web pages, where the htaccess file resides. Change fromAllowOverride None
toAllowOverride All
I had the same problem and found the answer and explanation on the Ubuntu Ask! forum https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working
In my experience, /var/www/ directory directive prevents subfolder virtualhost directives. So if you had tried all suggestions and still not working and you are using virtualhosts try this ;
1 - Be sure that you have
AllowOverride All
directive in/etc/apache2/sites-available/example.com.conf
2 - Check /var/www/ Directory directives in
/etc/apache2/apache2.conf
(possibly at line 164), which looks like ;If there is an
AllowOverride None
directive change it toAllowOverride All
or just escape lineuse RewriteBase /{your folder}/ on your .htaccess
Enable Apache mod_rewrite module
a2enmod rewrite
add the following code to
/etc/apache2/sites-available/default
AllowOverride All
Restart apache
/etc/init.d/apache2 restart
In
WampServer
Open WampServer Tray icon ----> Apache ---> Apache Modules --->rewrite_moduleFor Ubuntu,
First, run this command :-
Then, edit the file
/etc/apache2/sites-available/000-default.conf
using nano or vim using this command :-Then in the
000-default.conf
file, add this after the lineDocumentRoot /var/www/html
. If your root html directory is something other, then write that :-After doing everything, restart apache using the command
sudo service apache2 restart