Effacer mon .htaccess! J'hesite

Consultez la formation URL Rewriting et sites dynamiques de WebRankInfo / Ranking Metrics


Hoho
WRInaute impliqué
WRInaute impliqué
 
Messages: 515
Inscription: 10 Jan 2006

Effacer mon .htaccess! J'hesite

Message le Ven Jan 12, 2007 19:04

Bonjour.

Voila, je voudrais installer un petit hack pour l'URL rewriting sur mon systeme de news et voila que je bloque sur la 1ere etape lol..
Code: Tout sélectionner
1. Go to the directory which contains the file showing your news (let's call this file news.php).
If you already have a .htaccess file in this directory - delete it.
Make sure this directory is writable as the hack will automatically create a new .htaccess file.


Il me demande d'effacer mon .htacess 8O 8O Car mon systeme de news est sur l'index . Dont dingue non?

Devrais-je laisser tomber ou bien ya moyen de de recoller mon .htacess a la fin du hack.

Voici la mise à jour
Code: Tout sélectionner
1. Go to the directory which contains the file showing your news (let's call this file news.php).
If you already have a .htaccess file in this directory - delete it.
Make sure this directory is writable as the hack will automatically create a new .htaccess file.

2. Open news.php (file which shows your news) and find your include code:
For example:

#############################
$category = 2;
$number = 10;
$template = "Headlines";
include("cute/show_news.php");
#############################



3. Put this ABOVE your include code:
(You may change $path_to_data to point to your cutenews/data folder.)

#############################
//Mod_rewrite start
ob_start();

$path_to_data = "./data";

$url = $_GET['url'];
$test = find_archive(title_to_id($url));
$id = title_to_id($url);
$ucat = title_to_ucat($url);

//Mod_rewrite end
#############################



4. Put this BELOW your include code:
(You may change this line in the function below: $letter_replacements = array('ö' => 'oe', 'ä' => 'ae'); to convert certain characters of your language.)

#############################

//Mod_rewrite start

function replace_title($title){
$letter_replacements = array('ö' => 'oe', 'ä' => 'ae');
   $result = strtolower(strip_tags(html_entity_decode($title)));
   $result = strtr($result, $letter_replacements);
   $result = preg_replace('/\W/', "-", strip_tags($result));
   
   return $result;
}

function title_to_id($title){
global $path_to_data;

   if($handle = opendir($path_to_data."/archives"))
      while (false !== ($file = readdir($handle))){
         if($file != "." and $file != ".." and eregi("news", $file)){
            $files_arch[] = $path_to_data."/archives/$file";
         }
      }
   $files_arch[] = $path_to_data."/news.txt";

foreach($files_arch as $file){
   $all_news = file($file);
   foreach($all_news as $news_line){
      $news_arr = explode("|", $news_line);
      if(replace_title($news_arr[2]) == $title){

         return $news_arr[0];
      }
   }
}
}

function title_to_ucat($title){
global $path_to_data;
   $all_news = file($path_to_data."/news.txt");
   foreach($all_news as $news_line){
      $news_arr = explode("|", $news_line);
      if(replace_title($news_arr[2]) == $title){
         return $news_arr[6];
      }
   }
}

function find_archive($id){
global $path_to_data;

   if($handle = opendir($path_to_data."/archives"))
      while (false !== ($file = readdir($handle))){
         if($file != "." and $file != ".." and eregi("news", $file)){
            $files_arch[] = $path_to_data."/archives/$file";
         }
      }
   $files_arch[] = $path_to_data."/news.txt";

   foreach($files_arch as $file){
      $all_news_db = file("$file");
      foreach($all_news_db as $news_line){
         $news_arr = explode("|", $news_line);
         if($news_arr[0] == $id){
            if(ereg("([[:digit:]]{0,})\.news\.arch", $file, $regs)){ $archive = $regs[1]; }
            return $archive;
         }
      }
   }
}

function id_to_title($id, $archiv = false, $type, $page = ''){
global $path_to_data;

   if($archiv){
   $all_news = file($path_to_data."/archives/".$archiv.".news.arch");
   }
   else{
   $all_news = file($path_to_data."/news.txt");
   }
      
   foreach($all_news as $news_line){
      $news_arr = explode("|", $news_line);
      if($news_arr[0] == $id){
         $title = replace_title($news_arr[2]);
         if($type == "commentspage"){
            return "commentspage/".$page."/".$title.".html";
         }
         else
         return $type."/".$title.".html";
      }
   }
}

$show_news = ob_get_contents();
ob_get_clean();

$script_file = end($script_url = explode("/", $HTTP_SERVER_VARS['SCRIPT_NAME']));
$path = substr($HTTP_SERVER_VARS['SCRIPT_NAME'], 0, -strlen($script_file));

$find = array(   /*post*/         "#".$script_file."\?subaction=showfull&id=(.*?)&archive=&start_from=&ucat=(.*?)&#ie",
            /*postcomments*/   "#".$script_file."\?subaction=showcomments&id=(.*?)&archive=&start_from=&ucat=(.*?)&#ie",
            /*postpage*/      "#".$script_file."\?start_from=(.*?)&ucat=&archive=&subaction=&id=(.*?)&#i",
            /*archiveindex*/   "#".$script_file."\?archive=(.*?)&subaction=list-archive#i",
            /*archive*/         "#".$script_file."\?subaction=showfull&id=(.*?)&archive=(.*?)&start_from=&ucat=(.*?)&#ie",
            /*archivepage*/      "#".$script_file."\?start_from=(.*?)&ucat=&archive=(.*?)&subaction=list-archive&id=&#i",
            /*archivecomments*/   "#".$script_file."\?subaction=showcomments&id=(.*?)&archive=(.*?)&start_from=&ucat=(.*)&#ie",
            /*searchnews*/      "#".$script_file."\?misc=search&subaction=showfull&id=(.*?)&archive=&cnshow=news&ucat=(.*?)&start_from=&#ie",
            /*searcharchives*/   "#".$script_file."\?misc=search&subaction=showfull&id=(.*?)&archive=(.*?)&cnshow=news&ucat=(.*?)&start_from=&#ie",
            /*ncommentspage*/   "#".$script_file."\?comm_start_from=(.*?)&archive=&subaction=showcomments&id=(.*?)&ucat=(.*?)&#ie",
            /*acommentspage*/   "#".$script_file."\?comm_start_from=(.*?)&archive=(.*?)&subaction=showcomments&id=(.*?)&ucat=(.*?)&#ie",
         );

$replace = array(   "id_to_title('\\1', false, 'post')",
               "id_to_title('\\1', false, 'comments')",
               "postpage/\\1.html",
               "archiveindex/\\1.html",
               "id_to_title('\\1', '\\2', 'archive')",
               "archivepage/\\2/\\1.html",
               "id_to_title('\\1', '\\2', 'comments')",
               "id_to_title('\\1', false, 'post')",
               "id_to_title('\\1', '\\2', 'archive')",
               "id_to_title('\\2', false, 'commentspage', '\\1')",
               "id_to_title('\\3', '\\2', 'commentspage', '\\1')",
            );

$show_news = preg_replace($find, $replace, $show_news);
$show_news = str_replace("&url=".$url, '', $show_news);

if(!file_exists('.htaccess')){
$htaccess = "RewriteEngine On\n";
$htaccess .= "RewriteBase ".$path."\n\n";
$htaccess .= "RewriteRule ^post/(.*).html(.*)$ ".$script_file."?subaction=showfull&url=$1$2 [L,NC]\n";
$htaccess .= "RewriteRule ^postpage/(.*).html(.*)$ ".$script_file."?start_from=$1$2 [L,NC]\n\n";
$htaccess .= "RewriteRule ^comments/(.*).html(.*)$ ".$script_file."?subaction=showcomments&url=$1$2 [L,NC]\n";
$htaccess .= "RewriteRule ^commentspage/(.*)/(.*).html(.*)$ ".$script_file."?comm_start_from=$1&subaction=showcomments&url=$2$3 [L,NC]\n\n";
$htaccess .= "RewriteRule ^archiveindex/(.*).html(.*)$ ".$script_file."?archive=$1&subaction=list-archive$2 [L,NC]\n";
$htaccess .= "RewriteRule ^archive/(.*).html(.*)$ ".$script_file."?subaction=showfull&url=$1$2 [L,NC]\n";
$htaccess .= "RewriteRule ^archivepage/(.*)/(.*).html(.*)$ ".$script_file."?start_from=$2&archive=$1&subaction=list-archive$3 [L,NC]";

$file = fopen(".htaccess", "w");
fwrite($file, $htaccess);
fclose($file);
}

echo $show_news;
//Mod_rewrite end

######################################



5. Open show_archives.php and find this:
######################################
error_reporting (E_ALL ^ E_NOTICE);
######################################

add below:
######################################
//Mod rewrite
if($test != '') $archive = $test;
//Mod rewrite
######################################



6. Open show_news.php and find this:
######################################
error_reporting (E_ALL ^ E_NOTICE);
######################################

add below:
######################################
//Mod rewrite
if($test != '') $archive = $test;
//Mod rewrite
######################################



7. Open inc/shows.inc.php and find this:
######################################
echo "<script type=\"text/javascript\">window.location=\"$PHP_SELF?subaction=showfull&id=$id&ucat=$ucat&archive=$archive&start_from=$start_from&$user_query\";</script>";
######################################

replace with this:
######################################
echo "<script type=\"text/javascript\">window.location=\"$PHP_SELF\";</script>";
######################################


8. Open inc/shows.inc.php and find this:
######################################
$user_query = cute_query_string($QUERY_STRING, array( "comm_start_from","start_from", "archive", "subaction", "id", "ucat"));
######################################

add below:
######################################
if($user_query != "")
$user_query = "&".$user_query;
######################################


YoyoS
WRInaute accro
WRInaute accro
 
Messages: 3827
Inscription: 14 Sep 2006

Message le Ven Jan 12, 2007 19:40

Ben tu n'as qu'à le renommer ? Puis tu regardes les informations contenues dans ton nouveau htaccess, qu'il vient de créer, puis tu le supprimes et recopies dans l'ancien.

Ensuite, tu redonnes le bon nom au fichier que tu avais renommé, et c'est bon non ? :s


finstreet
WRInaute accro
WRInaute accro
 
Messages: 16999
Inscription: 10 Juil 2005

Message le Ven Jan 12, 2007 19:51

rien à rajouter

Tu le laisses créer le nouveau htacess et tu rebalanceras les infos du tien dedans ensuite ... y'a peu de chance qu'il y ait des lignes en doublon


Hoho
WRInaute impliqué
WRInaute impliqué
 
Messages: 515
Inscription: 10 Jan 2006

Message le Ven Jan 12, 2007 20:23

Oui c'est ce que je pensais .

Comme je ne peux pas examiner le code :S j'avais peur qu'il genere un nouveau .htaccess à chaque news posté, ce qui effacerait l'ancien.

Sinon je vais essayer ;) Rien de mieux que d'avoir ses reponses par l'experimentation.


YoyoS
WRInaute accro
WRInaute accro
 
Messages: 3827
Inscription: 14 Sep 2006

Message le Ven Jan 12, 2007 22:01

non je crois que c'est une seul fois à l'installation qu'il est créé :) Ca serait nouveau si il était modifié à chaque news !


Hoho
WRInaute impliqué
WRInaute impliqué
 
Messages: 515
Inscription: 10 Jan 2006

Message le Sam Jan 13, 2007 18:01

Encore un problème:
Make sure this directory is writable as the hack will automatically create a new .htaccess file.

Si je comprend bien je dois mettre un chmod 777 sur mon public_html.

Mais ils sont fous eux!! C'est risqué non?


finstreet
WRInaute accro
WRInaute accro
 
Messages: 16999
Inscription: 10 Juil 2005

Message le Sam Jan 13, 2007 20:19

ben c juste le temps de l'installation... tu remets en normal après


Hoho
WRInaute impliqué
WRInaute impliqué
 
Messages: 515
Inscription: 10 Jan 2006

Message le Sam Jan 13, 2007 20:29

Bon je te fais confiance. Si y'a un pépin, prépare toi à prendre un avocat. :lol:


finstreet
WRInaute accro
WRInaute accro
 
Messages: 16999
Inscription: 10 Juil 2005

Message le Sam Jan 13, 2007 20:43

Hoho a écrit:Bon je te fais confiance. Si y'a un pépin, prépare toi à prendre un avocat. :lol:


mais le htacess qu'il installe, il est pas sur un sous répertoire ? sinon oui les procédures d'installation sont toujours sensibles ...


Hoho
WRInaute impliqué
WRInaute impliqué
 
Messages: 515
Inscription: 10 Jan 2006

Message le Sam Jan 13, 2007 20:52

non il est sur la racine. Car mon systeme de news est sur l'index.


Si vous avez aimé cette discussion, partagez-la sur vos réseaux sociaux préférés :

Formation recommandée sur ce thème :

Formation URL Rewriting et sites dynamiques : apprenez comment mettre en place la réécriture d'URL, comment optimiser vos URL et profiter de vos pages dynamiques pour booster votre référencement. Formation animée par Olivier Duffez et Fabien Facériès, experts en référencement naturel.

Tous les détails sur le site Ranking Metrics : programme, prix, dates et lieux, inscription en ligne.

Lectures recommandées sur ce thème :



Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité