Files
shopPRO/docs/plans/2026-02-27-htaccess-to-routes-design.md
Jacek Pyziak a8175c0944 feat: eliminate htaccess.conf, move all URL routes to pp_routes (v0.329-0.330)
- Add category_id, page_id, article_id, type columns to pp_routes (migration 0.329)
- Move routing block in index.php before checkUrlParams() with Redis cache
- Routes for categories, pages, articles now stored in pp_routes instead of .htaccess
- Delete category/page/article routes on entity delete in respective repositories
- Eliminate libraries/htaccess.conf: generate .htaccess content entirely from PHP
- Move 32 static system routes (koszyk, logowanie, newsletter, AJAX modules, etc.)
  plus dynamic language/producer routes to pp_routes with type='system'
- Invalidate pp_routes Redis cache on every htacces() regeneration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 22:06:33 +01:00

5.8 KiB

Design: Eliminacja htaccess.conf i przeniesienie wszystkich tras do pp_routes

Data: 2026-02-27 Wersja docelowa: 0.330


Cel

Wyeliminowanie pliku libraries/htaccess.conf jako szablonu i przeniesienie wszystkich URL-i, które dotychczas były wpisane na sztywno w .htaccess, do tabeli pp_routes. Logika generowania .htaccess zostaje w całości w Helpers::htacces().


Co zostaje w .htaccess (reguły Apache-level)

Tylko dyrektywy, których PHP nie może obsłużyć:

  • RewriteEngine On, Options
  • Redirect HTTPS/www
  • Redirect HTTP→HTTPS (z wyłączeniem tpay-status, platnosc-status, przelewy24-status)
  • Usuwanie trailing slash (z wyłączeniem /admin/)
  • Routing /admin/admin/index.php
  • thumb/([0-9]*)/([0-9]*)/(.*)/libraries/thumb.php (inny plik PHP — niemożliwe przez pp_routes)
  • RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php — redirect z index.php
  • Blok cache headers (gzip, expires) — zależny od $settings['htaccess_cache']
  • Ochrona plików: <Files *.conf>, <Files *.log>, <Files *.ini>
  • Przekierowania 301 stron startowych (generowane dynamicznie w pętli pages)
  • Niestandardowe reguły z pp_settings (param=htaccess)
  • Catch-all: RewriteCond !-f, !-d, RewriteRule ^ index.php [L]

Co przechodzi do pp_routes

Statyczne trasy systemowe (hardcoded, niezmienne)

Pattern Destination
^wyszukiwarka/([^/]+)/([0-9]+)$ index.php?module=search&action=search_results&query=$1&bs=$2
^wyszukiwarka/([^/]+)$ index.php?module=search&action=search_results&query=$1&bs=1
^zamowienie/([a-zA-Z0-9-]+)$ index.php?module=shop_order&action=order_details&order_hash=$1
^potwierdzenie-platnosci/([a-zA-Z0-9-]+)$ index.php?module=shop_order&action=payment_confirmation&order_hash=$1
^tpay-status$ index.php?module=shop_order&action=payment_status_tpay
^platnosc-status$ index.php?module=shop_order&action=payment_status_hotpay
^przelewy24-status$ index.php?module=shop_order&action=payment_status_przelewy24pl
^koszyk$ index.php?module=shop_basket&action=main_view
^koszyk-podsumowanie$ index.php?module=shop_basket&action=summary_view
^zloz-zamowienie$ index.php?module=shop_basket&action=basket_save
^rejestracja$ index.php?module=shop_client&action=register_form
^logowanie$ index.php?module=shop_client&action=login_form
^wylogowanie$ index.php?module=shop_client&action=logout
^odzyskiwanie-hasla$ index.php?module=shop_client&action=recover_password
^panel-klienta/zamowienia$ index.php?module=shop_client&action=client_orders
^panel-klienta/adresy$ index.php?module=shop_client&action=client_addresses
^panel-klienta/nowy-adres$ index.php?module=shop_client&action=address_edit
^panel-klienta/edytuj-adres/([0-9]+)$ index.php?module=shop_client&action=address_edit&id=$1
^panel-klienta/usun-adres/([0-9]+)$ index.php?module=shop_client&action=address_delete&id=$1
^newsletter/signin$ index.php?module=newsletter&action=signin
^newsletter/confirm/hash=(.+)$ index.php?module=newsletter&action=confirm&hash=$1
^newsletter/unsubscribe/hash=(.+)$ index.php?module=newsletter&action=unsubscribe&hash=$1

Dwa wzorce na moduł — 3-segmentowy (z parametrami) i 2-segmentowy:

Pattern Destination
^shopBasket/([^/]+)/(.+)$ index.php?module=shopBasket&action=$1&$2
^shopBasket/([^/]+)$ index.php?module=shopBasket&action=$1
^shopClient/([^/]+)/(.+)$ index.php?module=shopClient&action=$1&$2
^shopClient/([^/]+)$ index.php?module=shopClient&action=$1
^shopProduct/([^/]+)/(.+)$ index.php?module=shopProduct&action=$1&$2
^shopProduct/([^/]+)$ index.php?module=shopProduct&action=$1
^shopCoupon/([^/]+)/(.+)$ index.php?module=shopCoupon&action=$1&$2
^shopCoupon/([^/]+)$ index.php?module=shopCoupon&action=$1
^search/([^/]+)/(.+)$ index.php?module=search&action=$1&$2
^search/([^/]+)$ index.php?module=search&action=$1

Dynamiczne trasy systemowe (wstawiane przy każdym htacces())

  • Języki: ^{lang_id}$index.php?a=change_language&id={lang_id} (per każdy aktywny język)
  • Producenci lista: ^producenci$index.php?module=shop_producer&action=list&layout_id={id}
  • Producent detail: ^producent/{slug}$ i ^producent/{slug}/([0-9]+)$ (per producent z DB)

Nowa kolumna type w pp_routes

ADD COLUMN type VARCHAR(20) NULL AFTER article_id
Wartość Znaczenie
NULL Trasa encji (produkt, kategoria, strona, artykuł)
'system' Trasa systemowa (wszystkie powyższe)

Zarządzanie: przy każdym htacces():

$mdb->delete('pp_routes', ['type' => 'system']); // usuń wszystkie
// ... wstaw na nowo (statyczne + dynamiczne)

Eliminacja htaccess.conf

file_get_contents($dir . 'libraries/htaccess.conf') zastąpione PHP stringiem z tą samą treścią (tylko Apache-level reguły). Placeholder {HTACCESS_CACHE} zastąpiony bezpośrednim if ($settings['htaccess_cache']) { ... } else { ... } wbudowanym w odpowiednim miejscu.

Plik libraries/htaccess.conf zostaje usunięty.


Pliki do modyfikacji

Plik Zmiana
migrations/0.329.sql Dodać ADD COLUMN type VARCHAR(20) NULL
Helpers::htacces() Usunąć file_get_contents, wbudować statyczny header, dodać inserty system routes, usunąć htaccess rules dla języków/newsletter/producenci
libraries/htaccess.conf Usunąć plik
docs/DATABASE_STRUCTURE.md Dodać kolumnę type do opisu pp_routes