Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Funkcja przepisywania adersów replace_for_mod_rewrite
pomek2
post
Post #1





Grupa: Zarejestrowani
Postów: 66
Pomógł: 0
Dołączył: 3.03.2007

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


Witam,
mam problem z replace_for_mod_rewrite a dokładnie z przepisywaniem adresów na proste

poniżej plik header.php

  1. if (eregi("header.php",$_SERVER['PHP_SELF'])) {
  2. Header("Location: index.php");
  3. die();
  4. }
  5.  
  6.  
  7.  
  8.  
  9. function replace_for_mod_rewrite(&$s)
  10. {
  11. $urlin =
  12. "'(?<!/)index.php'",
  13. "'(?<!/)modules.php'",
  14.  
  15. "'(?<!/)show.html\?name=Ads&op=add_ad_check'",
  16. "'(?<!/)show.html\?name=Ads&op=add_ad_photo'",
  17. "'(?<!/)show.html\?name=Ads&op=add_ad'",
  18. "'(?<!/)show.html\?name=Ads&op=search_advanced'",
  19. "'(?<!/)show.html\?name=Ads&op=show_item&id=([1-9][0-9]*)&title=([a-zA-Z0-9+]*)'",
  20. "'(?<!/)show.html\?name=Ads&op=edit_ad&ad_id=([1-9][0-9]*)'",
  21. "'(?<!/)show.html\?name=Ads&op=del_ad&func=check&id=([1-9][0-9]*)'",
  22. "'(?<!/)show.html\?name=Ads&op=edit_photo&ad_id=([1-9][0-9]*)'",
  23. "'(?<!/)show.html\?name=Ads&op=del_photo&ad_id=([1-9][0-9]*)&folder=([a-zA-Z0-9+]*)&photo=([a-zA-Z0-9+]*)__([1-9][0-9]*).jpg'",
  24. "'(?<!/)show.html\?name=Ads&op=del_photo&ad_id=([1-9][0-9]*)&folder=([a-zA-Z0-9+]*)&photo=([a-zA-Z0-9+]*).jpg'",
  25.  
  26. "'(?<!/)show.html\?name=Firm_Folder&rop=write_firm'",
  27. "'(?<!/)show.html\?name=Firm_Folder&rop=showcontent&id=([1-9][0-9+]*)&title=([/:|\s\-\'{}().&_a-zA-Z0-9+=]*)'",
  28. "'(?<!/)show.html\?name=Firm_Folder&rop=showcontent&id=([1-9][0-9+]*)'",
  29. "'(?<!/)show.html\?name=Firm_Folder&rop=mod_firm&id=([1-9][0-9+]*)'",
  30. "'(?<!/)show.html\?name=Firm_Folder&rop=del_firm&id_del=([1-9][0-9+]*)&title=([/:|\s\-\'{}().&_a-zA-Z0-9+=]*)'",
  31. "'(?<!/)show.html\?name=Firm_Folder&rop=postcomment&id=([1-9][0-9+]*)&title=([/:|\s\-\'{}().&_a-zA-Z0-9+=]*)'",
  32. "'(?<!/)show.html\?name=Firm_Folder&rop=del_comment&cid=([1-9][0-9+]*)&id=([1-9][0-9+]*)'",
  33. "'(?<!/)show.html\?name=Firm_Folder&rop=([a-zA-Z0-9+]*)&field=([a-zA-Z0-9+]*)&order=([a-zA-Z0-9+]*)'",
  34. "'(?<!/)show.html\?name=Firm_Folder&rop=([a-zA-Z0-9+]*)'",
  35. "'(?<!/)show.html\?name=Firm_Folder'",
  36.  
  37. "'(?<!/)show.html\?name=Your_Account&op=userinfo&username=([a-zA-Z0-9+]*)'",
  38. "'(?<!/)show.html\?name=Your_Account&amp;op=userinfo&username=([a-zA-Z0-9+]*)'",
  39. "'(?<!/)show.html\?name=Your_Account&amp;op=userinfo&amp;username=([a-zA-Z0-9+]*)'",
  40. "'(?<!/)show.html\?name=Your_Account&op=userinfo&bypass=([0-9]*)&username=([a-zA-Z0-9+]*)'",
  41. "'(?<!/)show.html\?name=Your_Account&amp;op=userinfo&bypass=([0-9]*)&username=([a-zA-Z0-9+]*)'",
  42. "'(?<!/)show.html\?name=Your_Account&amp;op=userinfo&amp;bypass=([0-9]*)&username=([a-zA-Z0-9+]*)'",
  43. "'(?<!/)show.html\?name=Your_Account&amp;op=userinfo&amp;bypass=([0-9]*)&amp;username=([a-zA-Z0-9+]*)'",
  44. "'(?<!/)show.html\?name=Your_Account&amp;op=pass_lost'",
  45. "'(?<!/)show.html\?name=Your_Account&op=pass_lost'",
  46. "'(?<!/)show.html\?name=Your_Account&file=index'",
  47. "'(?<!/)show.html\?name=Your_Account&op=logout'",
  48. "'(?<!/)show.html\?name=Your_Account&op=new_user'",
  49. "'(?<!/)show.html\?name=Your_Account'",
  50.  
  51. "'(?<!/)show.html\?name=Help'",
  52. "'(?<!/)pomoc.html&amp;myfaq=yes&amp;id_cat=([1-9][0-9]*)'",
  53. "'(?<!/)pomoc.html&myfaq=yes&id_cat=([1-9][0-9]*)'",
  54.  
  55. "'(?<!/)show.html\?name=FeedBack'",
  56. "'(?<!/)show.html\?name=Feedback'",
  57.  
  58. "'(?<!/)show.html\?name=Your_Account&file=index'",
  59. "'(?<!/)show.html\?name=Your_Account&op=logout'",
  60.  
  61. "'(?<!/)show.html\?name=Extant&extant=1'",
  62.  
  63. "'(?<!/)show.html\?name=Advertising&op=view_banner&cid=([1-9][0-9]*)&bid=([1-9][0-9]*)'",
  64. "'(?<!/)show.html\?name=Advertising&op=client_home'",
  65. "'(?<!/)show.html\?name=Advertising&op=client_report&cid=([1-9][0-9]*)&bid=([1-9][0-9]*)'",
  66. "'(?<!/)show.html\?name=Advertising&op=client'",
  67. "'(?<!/)show.html\?name=Advertising&op=plans'",
  68. "'(?<!/)show.html\?name=Advertising&op=terms'",
  69. "'(?<!/)show.html\?name=Advertising&op=sitestats'",
  70. "'(?<!/)show.html\?name=Advertising'",
  71.  
  72. "'(?<!/)show.html\?name=Content&pa=list_pages_categories&cid=1'",
  73. "'(?<!/)show.html\?name=Content&pa=list_pages_categories&cid=4'",
  74. "'(?<!/)show.html\?name=Content&pa=list_pages_categories&cid=2'",
  75. "'(?<!/)show.html\?name=Content'",
  76. );
  77.  
  78. $urlout = array(
  79. "index.html",
  80. "show.html",
  81.  
  82. "article\\1.html",
  83.  
  84. "sprawdzanie_ogloszenia.html",
  85. "dodawanie_zdjec.html",
  86. "dodaj_ogloszenie.html",
  87. "szukaj_ogloszenia.html",
  88. "ogloszenie_nr_\\1_\\2",
  89. "edytuj_ogloszenie_nr_\\1.html",
  90. "usun_ogloszenie_nr_\\1.html",
  91. "edytuj_zdjecia_nr_\\1.html",
  92. "usun_zdjecie_\\1_\\2_\\3_\\4.html",
  93. "usun_zdjecie_\\1_\\2_\\3.html",
  94.  
  95. "dodaj_firme.html",
  96. "firma_\\1_\\2.html",
  97. "firma_\\1.html",
  98. "edytuj_firme_id_\\1.html",
  99. "usun_firme_\\2_id_\\1.html",
  100. "komentarz_firmy_\\2_id_\\1.html",
  101. "usun_komentarz_firmy_\\1_\\2.html",
  102. "firmy_\\1_sort_\\2_\\3.html",
  103. "firmy_\\1.html",
  104. "katalog_firm.html",
  105.  
  106. "moje_konto-\\1.html",
  107. "moje_konto-\\1.html",
  108. "moje_konto-\\1.html",
  109. "moje_konto-\\1.html",
  110. "moje_konto-\\1.html",
  111. "moje_konto-\\1.html",
  112. "moje_konto-\\1.html",
  113. "zapomnialem_hasla.html",
  114. "zapomnialem_hasla.html",
  115. "moje_konto.html",
  116. "wyloguj.html",
  117. "rejestracja.html",
  118. "moje_konto.html",
  119.  
  120. "pomoc.html",
  121. "pomoc_\\1.html",
  122. "pomoc_\\1.html",
  123.  
  124. "kontakt.html",
  125. "kontakt.html",
  126.  
  127. "moje_konto.html",
  128. "wyloguj.html",
  129.  
  130. "wspolpraca_z_serwisem.html",
  131.  
  132. "reklama_banner_\\1_\\2.html",
  133. "reklama_konto.html",
  134. "reklama_raport_\\1_\\2.html",
  135. "reklama_logowanie.html",
  136. "reklama_plany_i_taryfy.html",
  137. "reklama_regulamin.html",
  138. "reklama_statystyki.html",
  139. "reklama.html",
  140.  
  141. "kredyty_samochodowe.html",
  142. "ubezpieczenia.html",
  143. "leasing.html",
  144. "finanse.html",
  145.  
  146. );
  147.  
  148. $s = preg_replace($urlin, $urlout, $s);
  149. return $s;
  150. }


a także wycinek z footer.php

  1.  
  2. $contents = ob_get_contents(); // store buffer in $contents
  3. ob_end_clean(); // delete output buffer and stop buffering
  4. echo replace_for_mod_rewrite($contents); //display modified buffer to screen
  5. global $dbg_starttime;


i htaccess

  1. DirectoryIndex index.php index.cgi index.pl index.shtml index.html
  2.  
  3. <Limit GET PUT POST>
  4. order allow,deny
  5.  
  6. allow from all
  7. </Limit>
  8.  
  9. # deny most common except .php
  10. <FilesMatch "\.(inc|tpl|h|ihtml|sql|ini|conf|class|bin|spd|theme|module|exe)$">
  11. deny from all
  12. </FilesMatch>
  13.  
  14. #Disable .htaccess viewing from browser
  15. <Files ~ "^\.ht">
  16. Order allow,deny
  17. Deny from all
  18. Satisfy All
  19. </Files>
  20.  
  21. <Files ~ "\config.php$">
  22. deny from all
  23. </Files>
  24.  
  25. #ErrorDocument 404 <a href="http://maxi-auto.pl" target="_blank">http://maxi-auto.pl</a>
  26.  
  27. RewriteEngine On
  28.  
  29.  
  30. #Articles
  31. RewriteRule ^article([1-9][0-9]*).* show.html?name=News&file=article&sid=$1
  32. RewriteRule ^article([1-9][0-9]*).* show.html?name=Ads&op=show_item&id=$1
  33.  
  34. #Ads
  35. RewriteRule ^regulamin.html show.html?name=Help&myfaq=yes&id_cat=3#7
  36. RewriteRule ^sprawdzanie_ogloszenia.html show.html?name=Ads&op=add_ad_check
  37. RewriteRule ^dodawanie_zdjec.html show.html?name=Ads&op=add_ad_photo
  38. RewriteRule ^dodaj_ogloszenie.html show.html?name=Ads&op=add_ad
  39. RewriteRule ^szukaj_ogloszenia.html show.html?name=Ads&op=search_advanced
  40. RewriteRule ^ogloszenie_nr_([1-9][0-9]*)_([a-zA-Z0-9+]*).html show.html?name=Ads&op=show_item&id=$1&title=$2
  41. RewriteRule ^edytuj_ogloszenie_nr_([1-9][0-9]*).html show.html?name=Ads&op=edit_ad&ad_id=$1
  42. RewriteRule ^usun_ogloszenie_nr_([1-9][0-9]*).html show.html?name=Ads&op=del_ad&func=check&id=$1
  43. RewriteRule ^edytuj_zdjecia_nr_([1-9][0-9]*).html show.html?name=Ads&op=edit_photo&ad_id=$1
  44. RewriteRule ^usun_zdjecie_([1-9][0-9]*)_([a-zA-Z0-9+]*)_([a-zA-Z0-9+]*).html show.html?name=Ads&op=del_photo&ad_id=$1&folder=$2&photo=$3.jpg
  45. RewriteRule ^usun_zdjecie_([1-9][0-9]*)_([a-zA-Z0-9+]*)_([a-zA-Z0-9+]*)_([1-9]*).html show.html?name=Ads&op=del_photo&ad_id=$1&folder=$2&photo=$3__$4.jpg
  46. RewriteRule ^sprzedaj.html show.html?name=Your_Account&redirect=modules.php?name=Ads&op=add_ad
  47. RewriteRule ^sprzedaj.html show.html?name=modules.php?name=Ads&op=add_ad
  48. RewriteRule ^wyloguj.html show.html?name=Your_Account&op=logout
  49.  
  50. #FIRM FOLDER
  51. RewriteRule ^katalog_firm.html show.html?name=Firm_Folder
  52. RewriteRule ^dodaj_firme.html show.html?name=Firm_Folder&rop=write_firm
  53. RewriteRule ^firma_([1-9][0-9+]*).html show.html?name=Firm_Folder&rop=showcontent&id=$1
  54. RewriteRule ^firma_([1-9][0-9+]*)_([/:|\s\-\'{}().&_a-zA-Z0-9+=]*).html show.html?name=Firm_Folder&rop=showcontent&id=$1&title=$2
  55. RewriteRule ^edytuj_firme_id_([1-9][0-9+]*).html show.html?name=Firm_Folder&rop=mod_firm&id=$1
  56. RewriteRule ^usun_firme_([/:|\s\-\'{}().&_a-zA-Z0-9+=]*)_id_([1-9][0-9+]*).html show.html?name=Firm_Folder&rop=del_firm&id_del=$2&title=$1
  57. RewriteRule ^firma_([1-9][0-9+]*)_p([1-9][0-9+]*).html show.html?name=Firm_Folder&rop=showcontent&id=$1&page=$2
  58. RewriteRule ^firmy_([a-zA-Z0-9+]*)_sort_([a-zA-Z0-9+]*)_([a-zA-Z0-9+]*).html show.html?name=Firm_Folder&rop=$1&field=$2&order=$3
  59. RewriteRule ^firmy_([a-zA-Z0-9+]*).html show.html?name=Firm_Folder&rop=$1
  60. RewriteRule ^komentarz_firmy_([/:|\s\-\'{}().&_a-zA-Z0-9+=]*)_id_([1-9][0-9+]*).html show.html?name=Firm_Folder&rop=postcomment&id=$2&title=$1
  61. RewriteRule ^usun_komentarz_firmy_([1-9][0-9+]*)_([1-9][0-9+]*).html show.html?name=Firm_Folder&rop=del_comment&cid=$1&id=$2
  62.  
  63. #HELP
  64. RewriteRule ^pomoc.html show.html?name=Help
  65. RewriteRule ^pomoc_([1-9][0-9]*).html show.html?name=Help&myfaq=yes&id_cat=$1
  66.  
  67. #Kontakt
  68. RewriteRule ^kontakt.html show.html?name=Feedback
  69.  
  70. #Your Account
  71. RewriteRule ^moje_konto.html show.html?name=Your_Account&file=index
  72. RewriteRule ^moje_konto.html show.html?name=Your_Account
  73. RewriteRule ^zapomnialem_hasla.html show.html?name=Your_Account&op=pass_lost
  74. RewriteRule ^wyloguj.html show.html?name=Your_Account&op=logout
  75. RewriteRule ^zapomnialem_hasla.html show.html?name=Your_Account&op=pass_lost
  76. RewriteRule ^moje_konto_([a-zA-Z0-9+]*).html show.html?name=Your_Account&op=userinfo&username=$1
  77. RewriteRule ^moje_konto_([a-zA-Z0-9+]*)_([1-9][0-9]*).html show.html?name=Your_Account&op=userinfo&bypass=$2&username=$1
  78. RewriteRule ^rejestracja.html show.html?name=Your_Account&op=new_user
  79.  
  80. #Wspolpraca
  81. RewriteRule ^wspolpraca_z_serwisem.html show.html?name=Extant&extant=1
  82.  
  83. #Reklama
  84. RewriteRule ^reklama_banner_([1-9][0-9+]*)_([1-9][0-9+]*).html show.html?name=Advertising&op=view_banner&cid=$1&bid=$2
  85. RewriteRule ^reklama_konto.html show.html?name=Advertising&op=client_home
  86. RewriteRule ^reklama_raport_([1-9][0-9+]*)_([1-9][0-9+]*).html show.html?name=Advertising&op=client_report&cid=$1&bid=$2
  87. RewriteRule ^reklama.html show.html?name=Advertising
  88. RewriteRule ^reklama_plany_i_taryfy.html show.html?name=Advertising&op=plans
  89. RewriteRule ^reklama_regulamin.html show.html?name=Advertising&op=terms
  90. RewriteRule ^reklama_statystyki.html show.html?name=Advertising&op=sitestats
  91. RewriteRule ^reklama_logowanie.html show.html?name=Advertising&op=client
  92.  
  93. #Finanse
  94. RewriteRule ^kredyty_samochodowe.html show.html?name=Content&pa=list_pages_categories&cid=1
  95. RewriteRule ^ubezpieczenia.html show.html?name=Content&pa=list_pages_categories&cid=4
  96. RewriteRule ^leasing.html show.html?name=Content&pa=list_pages_categories&cid=2
  97. RewriteRule ^finanse.html show.html?name=Content
  98.  
  99. RewriteRule ^index.html index.php
  100.  
  101. RewriteRule ^show.html modules.php
  102.  


i problem jest w tym że przepisuje adresy jednak nie zmienia ich właściwie tzn myli kolejności,
zamiast dodaj ogłoszenie jest dodaj zdjęcie

ok zamykam, doszedłem co było nie tak, dziękuję za zainteresowanie
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: 19.08.2025 - 18:12