简体   繁体   中英

500 Internal Server Error after changing AllowOverride to All in Ubuntu

My Project is working fine in Blue host shared hosting and as well in my XAMPP localhost.

For testing we moved the files to a local ubuntu server. But .htaccess not working in this ubuntu server.
Which means the files accesible with .php extention but 404 error when accesed without .php extention.

http://172.31.0.55/project/contact.php works, but
http://172.31.0.55/project/contact shows 404 error

This is the htaccess code I use.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /project/

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/project/$1.php -f
RewriteRule ^(.+?)/?$ /project/$1.php [L]
Options All -Indexes
RewriteCond %{HTTP_REFERER} !^http://(www\.)?172.31.0.55/project/ [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?172.31.0.55/project/.*$ [NC]


ErrorDocument 403 http://172.31.0.55/project/403-error
ErrorDocument 404 http://172.31.0.55/project/404-error


After some research I changed lines in /etc/apache2/apache2.conf

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride none
    Require all granted
</Directory>

to

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

But now its showing 500 Internal server error when tried to access http://172.31.0.55/project/

Server version is Apache/2.4.18 (Ubuntu) Its a PHP Website

I can see following codes in http://172.31.0.55/ Apache default page

The configuration layout for an Apache2 web server installation on Ubuntu systems is as follows:

/etc/apache2/
|-- apache2.conf
|       `--  ports.conf
|-- mods-enabled
|       |-- *.load
|       `-- *.conf
|-- conf-enabled
|       `-- *.conf
|-- sites-enabled
|       `-- *.conf

I tried changing from ip address to localhost in htaccess. But not working

I checked for File permission its rwx rwx rx

I made these changes referring https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working

By default, Apache prohibits using an .htaccess file to apply rewrite rules, so first you need to allow changes to the file. Open the default Apache configuration file using nano or your favorite text editor in this path /etc/apache2/sites-available/000-default.conf

$ sudo nano /etc/apache2/sites-available/000-default.conf

Inside that file, you will find a <VirtualHost *:80> block starting on the first line. Inside of that block, add the following new block so your configuration file looks like the following. Make sure that all blocks are properly indented.

<VirtualHost *:80>
<Directory /var/www/html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>

. . .
</VirtualHost>

Save and close the file. To put these changes into effect, restart Apache.

$ sudo systemctl restart apache2

I followed these steps and my issue resolved.

and also first

I had the same issue. After searching a lot I have found that @Doug Smythies's way perfectly work for me. Up vote.

So I go to the terminal and run the following code:

sudo a2enmod rewrite
sudo service apache2 restart And that's it. Hope this will help others.

<Directory /var/www/html/project1> Options Indexes FollowSymLinks AllowOverride All Order allow,deny allow from all Require all granted

remove project 1 from your directory name and then solve the problem.

在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM