Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [htaccess] Problem z przepisywaniem adresow
Forum PHP.pl > Forum > Przedszkole
karmelik
Witam,

mam dwa uklady stron:

http://strona.pl/krzesla.html
http://strona.pl/krzesla.html?strona=5

w htaccess musze zrobic zeby wszystko kierowalo na index.php, wyciagalo kategorie i numer podstrony jesli jest, wiec mam:
Kod
RewriteEngine on
DirectoryIndex index.php
RewriteCond $1 !^(index\.php|templatka|sitemap\.xml\.gz|robots\.txt|google*\.html)

RewriteRule ^([a-zA-Z0-9]+).html?page=([0-9]+)$ index.php?kategoria=$1&page=$2
RewriteRule ^([a-zA-Z0-9]+).html$ index.php?kategoria=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]



teraz jak wchodze na http://strona.pl/krzesla.html oraz jak wchodze na http://strona.pl/krzesla.html?strona=5 jest to samo:
Kod
Array
(
    [kategoria] => krzesla
)



Ale jak zakomentuje linijke:
Kod
RewriteRule ^([a-zA-Z0-9]+).html$ index.php?kategoria=$1


w stronie http://strona.pl/krzesla.html gdy wyswietlam $_GET mam:
Kod
Array
(
    [/krzesla_html] =>
)


na stronie http://strona.pl/krzesla.html?strona=5 dane $_GET zawieraja:
Kod
Array
(
    [/krzesla_html] =>
    [page] => 5
)


nie mam zielonego pojecia dla czego nie pobiera prawidlowo kategorii. Prosze o jakas podpowiedz chociaz co zle tutaj robie ...
Turson
Kod
RewriteRule ^([a-zA-Z0-9]+).html$ index.php?kategoria=$1

Wymuszasz tutaj, że adres może zawierać tylko jeden parametr

Nospor napisał fajny kod dla ładnych urli http://nospor.pl/ladne-urle.html
karmelik
@Turson, ok rozumiem. Ale jak usunę ta linijke tez źle działa. Zamiast kategoria=krzesla pobiera mi sie:
  1. (
  2. [/krzesla_html] =>
  3. )

jesli jest tylko linijka:
  1. RewriteRule ^([a-zA-Z0-9]+).html?page=([0-9]+)$ index.php?kategoria=$1&page=$2

i tego kompletnie nie rozumiem :/
trueblue
Kod
RewriteEngine on
DirectoryIndex index.php

RewriteCond %{REQUEST_URI} !^/(index\.php|templatka|sitemap\.xml\.gz|robots\.txt|google*\.html)
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9]+).html$
RewriteCond %{QUERY_STRING} page=([0-9]+)$
RewriteRule .* index.php?kategoria=$2&page=$3

RewriteCond %{REQUEST_URI} !^/(index\.php|templatka|sitemap\.xml\.gz|robots\.txt|google*\.html)
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9]+).html$
RewriteRule .* index.php?kategoria=$2


karmelik
Niestety w obu przypadkach wyświetla się z powyższym kodem:
  1. (
  2. [kategoria] =>
  3. )

czyli nic nie wyświetla niestety
trueblue
Kod
RewriteEngine on
DirectoryIndex index.php

RewriteCond %{REQUEST_URI} !^/(index\.php|templatka|sitemap\.xml\.gz|robots\.txt|google*\.html)
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9]+).html$
RewriteCond %{QUERY_STRING} strona=([0-9]+)$
RewriteRule .* index.php?kategoria=%1&page=%2

RewriteCond %{REQUEST_URI} !^/(index\.php|templatka|sitemap\.xml\.gz|robots\.txt|google*\.html)
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9]+).html$
RewriteRule .* index.php?kategoria=%1
karmelik
@trueblue dziękuję Ci bardzo za pomoc, ta druga część instrukcji działa prawidłowo, pobiera kategorie, jednak pierwsza nadal nie łapie parametru strona sad.gif niby wszystko wyglada dobrze ale nie dziala :/ w obu przypadkach mam:
  1. (
  2. [kategoriaa] => krzesla
  3. )
trueblue
Jak wygląda link w przypadku parametru ze stroną?
karmelik
http://strona.pl/krzesla.html?strona=5
trueblue
Niepotrzebnie skomplikowałem:

Kod
RewriteEngine on
DirectoryIndex index.php

RewriteCond %{REQUEST_URI} !^/(index\.php|templatka|sitemap\.xml\.gz|robots\.txt|google*\.html)
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9]+).html
RewriteRule .* index.php?kategoria=%1 [QSA]
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.