0

I am setting up my store on latest Magento 2.3.1 CE edition. Apache version: Apache/2.4.39 PHP version: 7.2.18 MySQL version: 10.1.40-MariaDB.

Also I am using Porto theme.

There is a strange problem I am facing for first time. In static block, if I use some JavaScript code like below or any other custom code

<script>document.write(new Date().getFullYear())</script>

Static Block Code and when I save it, I get error

404 error: Page not found.

404 error after saving static block

If I remove JavaScript code, and put simple text in para html tag, it gets saved successfully. I have used previous versions of Magento 2 and porto theme earlier also but never got such an error. Using Magento 2.3.1 for first time.

Is there any setting in this version of Magento to explicitly allow usage of JavaScript in static blocks?

  • have you tried using <script type="text/javascript"> opening script tag instead of plain script tag – fmsthird Jun 3 at 7:27
  • @magefms . Yes, I tried that too. But still get same 404 error. Updated my question with snapshots. Just FYI, I run following commands to deploy theme. php -d memory_limit=-1 bin/magento setup:upgrade ; php -d memory_limit=-1 -d display_errors=on bin/magento setup:static-content:deploy -s standard -vvv -f ; Do I also need to run compile command to deploy theme ? – Devanshu Jun 3 at 15:14
  • I think I got what is causing problem. I had enabled mod security and as soon as I disabled it for my sub domain on which I am testing, it allowed me to save the static block with javascript. What change shall I make in mod security settings/rules which can allow me to save the static block with javascript code? – Devanshu Jun 19 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.