31 $this->file = XOOPS_ROOT_PATH.
'/.htaccess';
33 if(strpos($_SERVER[
'SERVER_SOFTWARE'],
'Apache')!==FALSE){
35 if(!file_exists($this->file))
36 file_put_contents($this->file,
'');
40 $this->content = file_get_contents($this->file);
51 if(strpos($_SERVER[
'SERVER_SOFTWARE'],
'Apache')===FALSE)
52 $this->apache =
false;
54 if(function_exists(
'apache_get_modules')){
55 $mods = apache_get_modules();
56 if(!in_array(
'mod_rewrite', $mods))
57 $this->rewrite =
false;
60 if(!$this->apache || !$this->rewrite){
65 if(!preg_match(
"/RewriteEngine\s{1,}On/", $this->content))
66 $this->content .=
"\nRewriteEngine On\n";
68 $base = parse_url(XOOPS_URL.
'/');
69 $this->base = isset(
$base[
'path']) ? rtrim(
$base[
'path'],
'/').
'/' :
'/';
70 $rb =
"RewriteBase ".$this->base.
"\n";
72 if(strpos($this->content, $rb)===
false){
73 if(preg_match(
"/RewriteBase/", $this->content))
74 preg_replace(
"/RewriteBase\s{1,}(.*)\n",$rb, $this->content);
76 $this->content .= $rb.
"\n";
79 if(!preg_match(
"/RewriteCond\s{1,}\%\{REQUEST_URI\}\s{1,}\!\/\[A\-Z\]\+\-/", $this->content))
80 $this->content .=
"RewriteCond %{REQUEST_URI} !/[A-Z]+-\n";
82 if(!preg_match(
"/RewriteCond\s{1,}\%\{REQUEST_FILENAME\}\s{1,}\!\-f/", $this->content))
83 $this->content .=
"RewriteCond %{REQUEST_FILENAME} !-f\n";
85 if(!preg_match(
"/RewriteCond\s{1,}\%\{REQUEST_FILENAME\}\s{1,}\!\-d/", $this->content))
86 $this->content .=
"RewriteCond %{REQUEST_FILENAME} !-d\n";
96 if(strpos($this->content, $code)!==FALSE)
103 if(!preg_match(
"/\# begin $this->module\n(.*)\n\# end $this->module/i", $this->content, $match))
112 $code =
"# begin $this->module\n$this->rules\n# end $this->module\n";
119 if(
$rules==
'')
return false;
121 if(!$this->apache || !$this->rewrite)
141 if(!is_writable($this->file))
142 return $this->bCode.$code;
144 if($oldExists!==
false)
145 $this->content = str_replace($oldExists, $code, $this->content);
147 $this->content .=
"\n$code";
149 if(file_put_contents($this->file, $this->content))