Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][PHP]Przekierowanie na podstrone, http://localhost/index.php -> http://localhost/index.php?id=main
jerry1984
post
Post #1





Grupa: Zarejestrowani
Postów: 38
Pomógł: 3
Dołączył: 4.12.2010

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


Witam

Mam problemy z przekierowaniem z http://localhost/index.php na podstronę http://localhost/index.php?id=main .

Używałem wielu kombinacji:

.htaccess
Kod
Redirect permanent http://localhost/index.php  http://localhost/index.php?id=main


meta
Kod
<META HTTP-EQUIV=Refresh CONTENT=?0; URL=http://localhost/index.php?id=main?>

działa lecz mam nieskończoną pętle odświeżania strony.

php
Kod
<?
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://localhost/index.php?id=main");
header("Connection: close");
?>


Kurcze już mnie się pomysły kończą i odwiedzane strony.
Proszę o jakieś nakierowanie lub podpowiedz.

Z góry dziękuje

Ten post edytował jerry1984 15.05.2011, 12:44:18
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 15)
kokers
post
Post #2





Grupa: Zarejestrowani
Postów: 154
Pomógł: 33
Dołączył: 18.10.2010
Skąd: Katowice

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


a czemu chcesz przekierowac? rozumiem, że chcesz przekierować żeby było to id=main. Nie lepiej zrobić:

  1. if(!isset($_GET['id'])){
  2. $id='main';
  3. }else{
  4. $id = $_GET['id'];
  5. }


?


--------------------
‎"Sometimes you're gonna get odd error syntax, unexpected T_PAAMAYIM_NEKUDOTAYIM and you're like, what in the world is that thing i have no idea what went wrong in my code. In english that error means you screwed up the references to an object" Kevin Skoglund
Drobna prywata: Ależ nie nie, nie zamierzam zmieniać płci w najbliższym czasie, więc zwracanie się do mnie per Pan jest odrobinkę nietrafione.
Go to the top of the page
+Quote Post
matino
post
Post #3





Grupa: Zarejestrowani
Postów: 175
Pomógł: 30
Dołączył: 9.08.2007

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


RewriteEngine On
RewriteRule ^/index.php$ index.php?id=main [R=301,L]
redirect 301 /index.php http://localhost/index.php?id=main
Go to the top of the page
+Quote Post
jerry1984
post
Post #4





Grupa: Zarejestrowani
Postów: 38
Pomógł: 3
Dołączył: 4.12.2010

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


Cytat(kokers @ 15.05.2011, 14:24:56 ) *
a czemu chcesz przekierowac? rozumiem, że chcesz przekierować żeby było to id=main. Nie lepiej zrobić:

  1. if(!isset($_GET['id'])){
  2. $id='main';
  3. }else{
  4. $id = $_GET['id'];
  5. }


?


już wcześniej tak miałem i było by fajnie, lecz w niektórych podstronach wklejała mi się strona "main.php".
Obecnie używam
  1. if($_GET['id'] == 'main' ) {
  2. include('user/main.php');
  3. }


bo jak wklepuję http://localhost/ mam pustą stronkę dlatego potrzebuje redirect do http://localhost/index.php?id=main gdzie jest powitalna strona.

Cytat
RewriteEngine On
RewriteRule ^/index.php$ index.php?id=main [R=301,L]
redirect 301 /index.php http://localhost/index.php?id=main


Jak zwykle .htacces wywala błąd "Błąd serwera"
Go to the top of the page
+Quote Post
melkorm
post
Post #5





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


W tym IF'ie daj:
  1. trim($_SERVER['REQUEST_URI'],'/') == 'index.php'


--------------------
Go to the top of the page
+Quote Post
jerry1984
post
Post #6





Grupa: Zarejestrowani
Postów: 38
Pomógł: 3
Dołączył: 4.12.2010

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


Cytat(melkorm @ 15.05.2011, 15:18:20 ) *
W tym IF'ie daj:
  1. trim($_SERVER['REQUEST_URI'],'/') == 'index.php'


A do którego mam dodać co podał @kokers, czy do tego co ja używam ?

Jeśli do mojego to oto CI chodzi :

  1. if($_GET['id'] == 'main' )
  2. trim($_SERVER['REQUEST_URI'],'/') == 'index.php'{
  3. include('user/main.php');
  4. }


?
Go to the top of the page
+Quote Post
melkorm
post
Post #7





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


  1. if($_GET['id'] == 'main' )
  2. trim($_SERVER['REQUEST_URI'],'/') == 'index.php'{
  3. include('user/main.php');
  4. }

Przecież to nawet nie jest poprawne ... .


  1. if( $_GET['id'] == 'main' || trim($_SERVER['REQUEST_URI'],'/') == 'index.php')
  2. {
  3. include('user/main.php');
  4. }


Ten post edytował melkorm 15.05.2011, 14:40:40


--------------------
Go to the top of the page
+Quote Post
jerry1984
post
Post #8





Grupa: Zarejestrowani
Postów: 38
Pomógł: 3
Dołączył: 4.12.2010

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


Cytat(melkorm @ 15.05.2011, 15:40:24 ) *
  1. if( $_GET['id'] == 'main' || trim($_SERVER['REQUEST_URI'],'/') == 'index.php')
  2. {
  3. include('user/main.php');
  4. }


Fajnie, tylko działa identycznie jak wcześniejsza moja forma, nadal brak przekierowania do lokalizacji (index.php?id=main) nawet po paru modyfikacji.

Kurcze nie wiedziałem, że będą aż takie duże problemy sadsmiley02.gif
Go to the top of the page
+Quote Post
melkorm
post
Post #9





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


to zrób z rewritem ...
Cytat
RewriteEngine On
RewriteRule index.php$ /index.php?id=main [NC,L]


--------------------
Go to the top of the page
+Quote Post
jerry1984
post
Post #10





Grupa: Zarejestrowani
Postów: 38
Pomógł: 3
Dołączył: 4.12.2010

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


Również nie działa, a robię tak:

Kod
RewriteEngine On
RewriteRule http://localhost/index.php$ /http://localhost/index.php?id=main [NC,L]


wiec jak widzisz, oporny jest sciana.gif już 3h mija, a ja siedzę z tym durnym problemem.
Go to the top of the page
+Quote Post
melkorm
post
Post #11





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


bez pełnych adresów .... sprawdzałeś to co wkleiłem?

P.S. w adresie będzie widoczne tylko index.php ale w GET dostanie id=main.


--------------------
Go to the top of the page
+Quote Post
jerry1984
post
Post #12





Grupa: Zarejestrowani
Postów: 38
Pomógł: 3
Dołączył: 4.12.2010

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


Cytat(melkorm @ 15.05.2011, 16:45:13 ) *
bez pełnych adresów .... sprawdzałeś to co wkleiłem?

P.S. w adresie będzie widoczne tylko index.php ale w GET dostanie id=main.


tak sprawdzałem i wywala
Kod
The requested URL /index.php was not found on this server.


Go to the top of the page
+Quote Post
melkorm
post
Post #13





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


to daj ./index.php


--------------------
Go to the top of the page
+Quote Post
jerry1984
post
Post #14





Grupa: Zarejestrowani
Postów: 38
Pomógł: 3
Dołączył: 4.12.2010

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


Cytat(melkorm @ 15.05.2011, 17:30:15 ) *
to daj ./index.php


już lepiej, strona się wczytuje bez błędów, lecz bez przekierowania.
Próbowałem też dać tak :

Kod
RewriteEngine On
RewriteRule ./index.php$ ./index.php?id=main [NC,L]


i też nic.
Go to the top of the page
+Quote Post
melkorm
post
Post #15





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


to też Tobie mówię że to NIE jest przekierowanie tylko przepisanie adresu czyli: widzisz index.php a PHP widzi index.php?id=main .

Jeżeli chcesz przekierowanie to daj:
Kod
RewriteRule index.php$ ./index.php?id=main [R=301,NC,L]



--------------------
Go to the top of the page
+Quote Post
Atomic_Cookie`
post
Post #16





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 26.06.2010
Skąd: Polska

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


  1. if (!isset($_GET['id'])) header('location: ?id=main');


--------------------
Have a Иice day
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 21.08.2025 - 17:06