Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: .htaccess - Przekierowanie
Forum PHP.pl > Forum > Serwery WWW > Apache
reptile_rex
Witam,

Potrzebuję napisać taką regułkę, że gdy w adresie posiadamy przykładowo:

/mleko/ to wtedy kierujemy na /Mleko/index.php/$1

W przeciwnym wypadku kierujemy na /App/index.php/$1

Bardzo bym prosił o wskazówkę.

Dziękuję
404
Z tego co widzę to na tym forum gotowców się nie daje, więc:
http://httpd.apache.org/docs/current/mod/m...tml#rewriterule
http://www.php.rk.edu.pl/w/p/modrewrite-krotkie-urle/
reptile_rex
Potrzebuję wskazówki na temat "w przeciwnym wypadku" bo przykładowo mogę sobie zrobić:

RewriteRule ^mleko(.*)$ /Mleko/index.php/$1 [L]

Ale jak teraz zrobić "w innym wypadku" na /App/index.php/$1
404
Analogicznie do tego, co zrobiłeś wyżej smile.gif Jeżeli nie wiesz jak to zrobić to znaczy, że nie rozumiesz własnego kodu, bo rozwiązanie Twojego problemu już masz.
webdice
Dodaj na końcu:

Kod
RewriteRule ^.*$ /App/index.php/$1 [L]
reptile_rex
No właśnie też tak logicznie myślałem, ale otrzymuję 500.

Całość:

  1. RewriteEngine On
  2. RewriteRule ^cms /Cms/index.php/$1 [L]
  3. RewriteRule ^.*$ /App/index.php/$1 [L]



Otrzymałem odpowiedź na Stackoverflow i umieszczam rozwiązanie poniżej.
Dzięki wszystkim zainteresowanym

Cytat
Note that apache doesn't run the rewrite-rules just once. It tries applying the rules until the url no longer changes (this makes mod_rewrite extremely powerful). That is why you get the error. The rules are creating a redirect loop.

e.g /cms/test directs to /Cms/index.php/test, which in turn is matches by the second rule, causing it to direct to /App/index.php/Cms/index.php/test, this url get matched again by the second rule, directing it to /App/index.php/App/index.php/Cms/index.php/test etc.

To prevent this loop, add a rewrite-condition:

  1. RewriteEngine On
  2. RewriteRule ^cms /Cms/index.php/$1 [L]
  3. RewriteCond %{REQUEST_URI} !^/(Cms|App)
  4. RewriteRule ^.*$ /App/index.php/$1 [L]
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.