Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [htaccess] Problem z przepisywaniem adresow
karmelik
post
Post #1





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 2.12.2014

Ostrzeżenie: (0%)
-----


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 ...
Go to the top of the page
+Quote Post
Turson
post
Post #2





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
karmelik
post
Post #3





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 2.12.2014

Ostrzeżenie: (0%)
-----


@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 :/
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 807
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


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


Go to the top of the page
+Quote Post
karmelik
post
Post #5





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 2.12.2014

Ostrzeżenie: (0%)
-----


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

czyli nic nie wyświetla niestety
Go to the top of the page
+Quote Post
trueblue
post
Post #6





Grupa: Zarejestrowani
Postów: 6 807
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
karmelik
post
Post #7





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 2.12.2014

Ostrzeżenie: (0%)
-----


@trueblue dziękuję Ci bardzo za pomoc, ta druga część instrukcji działa prawidłowo, pobiera kategorie, jednak pierwsza nadal nie łapie parametru strona (IMG:style_emoticons/default/sad.gif) niby wszystko wyglada dobrze ale nie dziala :/ w obu przypadkach mam:
  1. (
  2. [kategoriaa] => krzesla
  3. )
Go to the top of the page
+Quote Post
trueblue
post
Post #8





Grupa: Zarejestrowani
Postów: 6 807
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Jak wygląda link w przypadku parametru ze stroną?
Go to the top of the page
+Quote Post
karmelik
post
Post #9





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 2.12.2014

Ostrzeżenie: (0%)
-----


http://strona.pl/krzesla.html?strona=5
Go to the top of the page
+Quote Post
trueblue
post
Post #10





Grupa: Zarejestrowani
Postów: 6 807
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


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]


Ten post edytował trueblue 8.04.2015, 11:13:01
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 22:32