PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 27, 2022

[FIXED] Where to put rewrite rules in prestashop 1.7 .htaccess?

 October 27, 2022     .htaccess, apache, php, prestashop, prestashop-1.7     No comments   

Issue

Prestashop 1.7.2.4

After installation, the first lines of the generated .htaccess contains the following content:

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums

<IfModule mod_rewrite.c> ... ..

When I install one of the modules, it adds its own rewrite rules at the end of the .htaccess. This is done using PHP file functions (file_put_contents, file_get_contents) but with an append option. Unfortunately, this don't work until you put the rules on the top of the .htaccess file ( to precede some other rules that concern the same pattern). So I changed the behavior of module to prepend instead of appending.

The problem: I don't understand the comments by PS at the beginning of .htaccess. Does it mean module rules should necessarily be appended at the end(like module authors did)?


Solution

There is a lot of confusion we face since PrestaShop 1.5 whether a customized .htaccess file gets overwritten by PrestaShop during .htaccess generation or not.

In fact, PrestaShop will not overwrite changes in the .htaccess file if they custom rules are put in the correct places: Before or after the automatically generated rule mappings!

Example: .htaccess

Your custom rules

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again 
...
... auto-generated rules
...
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

Your custom rules

PS: Changing core functionality sounds pretty bad.



Answered By - wp78de
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing