magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

.htaccess Issues #35205

Closed nomuprive closed 2 years ago

nomuprive commented 2 years ago

Magento only loads when .htaccess file is disabled. I have tried tracking the issue in vain. Any suggestion? Anyone had this issue before? How did you resolve that?

m2-assistant[bot] commented 2 years ago

Hi @williambize. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

nomuprive commented 2 years ago

Magento only loads when .htaccess file is disabled. I have tried tracking the issue in vain. Any suggestion? Anyone had this issue before? How did you resolve that?

m2-assistant[bot] commented 2 years ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 2 years ago

Hello @williambize,

Thanks for posting the issue!

But we need more information in order to reproduce the issue. Normally with Apache server if mod_rewrite is enabled the Magento instance is working fine. Please tell us more about the following:

Thanks

nomuprive commented 2 years ago

Hi @engcom-Hotel

Thanks for the reply.

I have finished updating Magento to version 2.4.0, successfully. But when I tried to access the webstore, it was giving 500 error. I troubleshoot so many things, including...

But nothing changed. So I renamed the .htaccess file and the site started loading. But when I enable the .htaccess again, the site started giving 500 error again. So I believe the issue is with the .htaccess file. I have gone through the entire .htaccess file to make sure everything is fine, including "RewriteEngine on".

Below is the content of the .htaccess file

`############################################

overrides deployment configuration mode value

use command bin/magento deploy:mode:set to switch modes

SetEnv MAGE_MODE developer

############################################

uncomment these lines for CGI mode

make sure to specify the correct cgi php binary file name

it might be /cgi-bin/php-cgi

Action php5-cgi /cgi-bin/php5-cgi

AddHandler php5-cgi .php

############################################

Hosting specific options

Options -MultiViews

you might also need to add this line to php.ini

cgi.fix_pathinfo = 1

if it still doesn't work, rename php.ini to php5.ini

############################################

this line is specific for 1and1 hosting

#AddType x-mapp-php5 .php
#AddHandler x-mapp-php5 .php

############################################

enable usage of methods arguments in backtrace

SetEnv MAGE_DEBUG_SHOW_ARGS 1

############################################

default index file

DirectoryIndex index.php
############################################ ## adjust memory limit php_value memory_limit 756M php_value max_execution_time 18000 ############################################ ## disable automatic session start ## before autoload was initialized php_flag session.auto_start off ############################################ ## enable resulting html compression #php_flag zlib.output_compression on ########################################### ## disable user agent verification to not break multiple image upload php_flag suhosin.session.cryptua off ########################################### ## disable POST processing to not break multiple image upload SecFilterEngine Off SecFilterScanPOST Off ############################################ ## enable apache served files compression ## http://developer.yahoo.com/performance/rules.html#gzip # Insert filter on all content ###SetOutputFilter DEFLATE # Insert filter on selected content types only #AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json image/svg+xml # Netscape 4.x has some problems... #BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems #BrowserMatch ^Mozilla/4\.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # Don't compress images #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary # Make sure proxies don't deliver the wrong content #Header append Vary User-Agent env=!dont-vary ############################################ ## make HTTPS env vars available for CGI mode SSLOptions StdEnvVars

############################################

workaround for Apache 2.4.6 CentOS build when working via ProxyPassMatch with HHVM (or any other)

Please, set it on virtual host configuration level

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

############################################

############################################ enable rewrites Options +FollowSymLinks RewriteEngine on ############################################ ## you can put here your magento root folder ## path relative to web root #RewriteBase /magento/ ############################################ ## workaround for HTTP authorization ## in CGI environment RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] ############################################ ## TRACE and TRACK HTTP methods disabled to prevent XSS attacks RewriteCond %{REQUEST_METHOD} ^TRAC[EK] RewriteRule .* - [L,R=405] ############################################ ## redirect for mobile user agents #RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$ #RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC] #RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302] ############################################ ## never rewrite for existing files, directories and links RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l ############################################ ## rewrite everything else to index.php RewriteRule .* index.php [L]

############################################

Prevent character encoding issues from server overrides

If you still have problems, use the second line instead

AddDefaultCharset Off
#AddDefaultCharset UTF-8
AddType 'text/html; charset=UTF-8' html
############################################ ## Add default Expires header ## http://developer.yahoo.com/performance/rules.html#expires ExpiresDefault "access plus 1 year" ExpiresByType text/html A0 ExpiresByType text/plain A0

###########################################

Deny access to root files to hide sensitive application information

RedirectMatch 403 /\.git

<Files composer.json>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files composer.lock>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files .gitignore>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files .htaccess>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files .htaccess.sample>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files .php_cs.dist>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files .travis.yml>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files CHANGELOG.md>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files COPYING.txt>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files Gruntfile.js>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files LICENSE.txt>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files LICENSE_AFL.txt>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files nginx.conf.sample>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files package.json>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files php.ini.sample>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files README.md>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files magento_umask>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files auth.json>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>
<Files .user.ini>
    <IfVersion < 2.4>
        order allow,deny
        deny from all
    </IfVersion>
    <IfVersion >= 2.4>
        Require all denied
    </IfVersion>
</Files>

For 404s and 403s that aren't handled by the application, show plain 404 response

ErrorDocument 404 /pub/errors/404.php ErrorDocument 403 /pub/errors/404.php

################################

If running in cluster environment, uncomment this

http://developer.yahoo.com/performance/rules.html#etags

#FileETag none

INTERNET EXPLORER

----------------------------------------------------------------------

| Document modes |

----------------------------------------------------------------------

Force Internet Explorer 8/9/10 to render pages in the highest mode

available in the various cases when it may not.

#

https://hsivonen.fi/doctype/#ie8

#

(!) Starting with Internet Explorer 11, document modes are deprecated.

If your business still relies on older web apps and services that were

designed for older versions of Internet Explorer, you might want to

consider enabling Enterprise Mode throughout your company.

#

https://msdn.microsoft.com/en-us/library/ie/bg182625.aspx#docmode

http://blogs.msdn.com/b/ie/archive/2014/04/02/stay-up-to-date-with-enterprise-mode-for-internet-explorer-11.aspx

Header set X-UA-Compatible "IE=edge" # `mod_headers` cannot match based on the content-type, however, # the `X-UA-Compatible` response header should be send only for # HTML documents and not for the other resources. Header unset X-UA-Compatible

`

Any suggestion?

Thanks

engcom-Hotel commented 2 years ago

Hello @williambize,

The content of .htaccess seems fine to me. Can you please check the Apache logs when .htaccess is enabled?

Thanks

nomuprive commented 2 years ago

@engcom-Hotel below the content of the Web Server Error. For safety reasons, I have replaced the domain name with "example.com" and the cPanel account username with "cpanelaccountuser"

[Wed Mar 23 06:20:57.013140 2022] [core:alert] [pid 5670] [client 192.241.223.177:60610] /home/cpanelaccountuser/public_html/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration [Wed Mar 23 06:20:57.012912 2022] [core:alert] [pid 5670] [client 192.241.223.177:60610] /home/cpanelaccountuser/public_html/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration [Wed Mar 23 06:07:29.029473 2022] [core:alert] [pid 7591] [client 45.146.165.37:45042] /home/cpanelaccountuser/public_html/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration [Wed Mar 23 06:07:29.029176 2022] [core:alert] [pid 7591] [client 45.146.165.37:45042] /home/cpanelaccountuser/public_html/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration [Wed Mar 23 05:46:00.449621 2022] [core:alert] [pid 5670] [client 172.70.230.72:21566] /home/cpanelaccountuser/public_html/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration, referer: https://example.com/ [Wed Mar 23 05:46:00.449300 2022] [core:alert] [pid 5670] [client 172.70.230.72:21566] /home/cpanelaccountuser/public_html/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration, referer: https://example.com/ [Wed Mar 23 05:46:00.351960 2022] [core:alert] [pid 7589] [client 172.70.230.42:39918] /home/cpanelaccountuser/public_html/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration, referer: https://example.com/ [Wed Mar 23 05:46:00.351719 2022] [core:alert] [pid 7589] [client 172.70.230.42:39918] /home/cpanelaccountuser/public_html/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration, referer: https://example.com/

engcom-Hotel commented 2 years ago

Hello @williambize,

As per looking into the logs, this issue may be due to the below line from the .htaccess file:

SetEnv MAGE_DEBUG_SHOW_ARGS 1

This may be due to mod_env not being installed on the server. Please try to install this Apache module and check if the issue has been resolved.

Thanks

nomuprive commented 2 years ago

Hi @engcom-Hotel Thanks for the support.

Unfortunately, installing mod_env did not resolve the issue.

Thanks

engcom-Hotel commented 2 years ago

Hello @williambize,

Actually I suggested you the solution according to the logs. Can you please check your error logs for any other error?

Thanks

nomuprive commented 2 years ago

@engcom-Hotel

  1. There was a problem in the .htaccess file... there was a </IfModule> without <IfModule> . So I had to remove "" from one of the lines in the .htaccess file.

  2. It appeared also that the cPanel account was not owning the folders and the files, so I ran the following command to make the user own the account, folders and files chown -Rv username:username /home/username/public_html

  3. After doing the above things, the 500 error seems to change to a different error message. I started getting the following error This page isn’t working, shop.example.com is currently unable to handle this request. HTTP ERROR 500

  4. So when I checked Apache errors, I found the following error: [Thu Apr 07 04:37:21.539071 2022] [core:crit] [pid 1807] (13)Permission denied: [client 185.189.182.234:41898] AH00529: /home/username/public_html/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/home/username/public_html/' is executable

The current error seems to be permission related, but I just run all the permission below and is still showing that 500 error message.

chmod -R 777 pub var find . -type f -exec chmod 644 {} \; find . -type d -exec chmod 755 {} \; find ./var -type d -exec chmod 777 {} \; find ./pub/media -type d -exec chmod 777 {} \; find ./pub/static -type d -exec chmod 777 {} \; chmod 777 ./app/etc chmod 644 ./app/etc/*.xml chmod u+x bin/magento

engcom-Hotel commented 2 years ago

Hello @williambize,

This doesn't seems to be a Magento codebase issue. I request you to please check this with your hosting provider.

Thanks

engcom-Hotel commented 2 years ago

Dear @williambize,

We have noticed that this issue has not been updated for a period of 14 Days. Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.

Regards