htaccess bzw. mod_rewrite-hilfe // url umschreiben

steff0rn

Lieutenant
Registriert
Jan. 2004
Beiträge
589
Zuletzt bearbeitet:
.htaccess
Code:
RewriteEngine On
RewriteBase <basis-url>

RewriteRule ^(.*)$ index.php
und ne kleine selbstgeschrieben seo klasse, damit das ganze kauderwelsch dann richtig angesprochen werden kann.
PHP:
<?php
  
  class SEO
  {
    protected $RequestURI;
    protected $RequestData;
    protected $Mappings;
    protected $Offset;
    
    public function __construct()
    {
      $this->Mappings = array();
      $this->Offset = 0;
      
      $this->SetRequestURI();
      $this->SetRequestData();
    }
    
    public function __destruct()
    {
    }
    
    public function __toString()
    {
      return '\'SEO\' object';
    }
    
    public function GetRequestData() { return $this->RequestData; }
    public function GetMapping( $Name ) { return (isset( $this->Mappings[$Name] ) ? $this->Mappings[$Name] : ''); }
    public function GetMappings() { return $this->Mappings; }
    
    protected function SetRequestURI() { $this->RequestURI = explode( '/', $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ); }
    protected function SetRequestData()
    {
      foreach( $this->RequestURI as $key => $value )
        if( strpos( $value, ':' ) !== false )
        {
          $var = explode( ':', $value );
          $this->RequestData[$var[0]] = $var[1];
          $this->Mappings[$var[0]] = $var[1];
        }
        else $this->RequestData[$key]= $value;
    }
    public function SetMap( $Name, $Parameter ) { $this->Mappings[$Name] = $this->RequestData[(is_string( $Parameter ) ? $Parameter : $this->Offset + $Parameter)]; }
    public function SetOffset( $Offset ) { $this->Offset = $Offset; }
  }
  
?>
beispielanwendung:
PHP:
<?php
  
  function _print_r( $Data, $Add = '' ) { echo '<pre>'.(!empty( $Add ) ? $Add.' : ' : '').print_r( $Data, true ).'</pre>'; }
  
  require_once './SEO.php';
  
  $SEO = new SEO();
  $SEO->SetOffset( 2 );
  
  _print_r( $SEO->GetRequestData(), '$RequestData' );
  _print_r( $SEO->GetMappings(), '$Mappings' );
  
  $SEO->SetMap( 'page', 0 );
  $SEO->SetMap( 'area', 1 );
  $SEO->SetMap( 'area2', 2 );
  $SEO->SetMap( 'vendor', 3 );
  $SEO->SetMap( 'year', 4 );
  $SEO->SetMap( 'month', 5 );
  
  _print_r( $SEO->GetMappings(), '$Mappings' );
  
?>
beispielaufruf: http://foo.bar/news/hardware/cpu/amd/2009/04/content:neue cpus
inhalt:
$Mappings : Array
(
[content] => neue%20cpus
[page] => news
[area] => hardware
[area2] => cpu
[vendor] => amd
[year] => 2009
[month] => 04
)
 
Zuletzt bearbeitet:

Ähnliche Themen

Zurück
Oben