I have a section where I want to edit the .htaccess file using a <textarea>
field ... but here comes the problem, this is my original htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
order deny,allow
deny from all
allow from 187.192.43.11 # Oficina NUEVA
allow from 187.192.43.39 # Oficina NUEVA
</IfModule>
ErrorDocument 401 /admin/errors/error.php
ErrorDocument 403 /admin/errors/error.php
ErrorDocument 404 /admin/errors/error.php
ErrorDocument 500 /admin/errors/error.php
And when I save it, I keep it in the database like this:
<IfModule>
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
order deny,allow
deny from all
allow from 187.192.43.11 # Oficina NUEVA
allow from 187.192.43.39 # Oficina NUEVA
</IfModule>
ErrorDocument 401 /admin/errors/error.php
ErrorDocument 403 /admin/errors/error.php
ErrorDocument 404 /admin/errors/error.php
ErrorDocument 500 /admin/errors/error.php
I do not know why you save this <IfModule>
instead of this <IfModule mod_rewrite.c>
My view:
<form id="form" name="form" action="<?=base_url()?>controlip/guardarhtaccess" method="POST">
<!---->
<input type="hidden" name="idhtaccess" value="">
<!---->
<input type="hidden" name="fechamodificacionhtaccess" value="<?php echo date('d-m-Y');?>">
<!---->
<textarea style="height: 500px;" class="input_edit_client" name="contenidohtaccess" id="contenidohtaccess">
<?php
$archivo = file_get_contents("../admin/.htaccess");
$archivo = ucfirst($archivo);
echo $archivo;
?>
</textarea>
<!---->
<br>
<!---->
<input class="btn_save_edit" type="submit" name="guardar" id="guardar" value="GUARDAR" style="margin-bottom: -15px;background: #252525;margin-top: 10px;font-size: 14px;padding: 5px 15px;">
<!---->
</form>
My controller:
function guardarhtaccess(){
$contenidohtaccess=$this->input->post('contenidohtaccess',TRUE);
$fichero = "/homessd/wwwhr1/public_html/admin/prueba.txt";
file_put_contents($fichero, $contenidohtaccess);
$data= array(
'idhtaccess' =>0,
'fechamodificacionhtaccess' => time(),
'contenidohtaccess' =>$this->input->post('contenidohtaccess',TRUE),
);
$this-> realhtaccess -> savehtaccess($data);
redirect('controlip');
}
My model:
function savehtaccess($data)
{
if($data[$this->ID]==0)
{
if($this->db->insert($this->Table, $data))
{
return true;
}
else
return false;
}
else
{
$this -> db -> where($this->ID, $data[$this->ID]);
$this -> db -> update($this->Table,$data);
}
}
and then the problem I have is that I delete this "mod_rewrite.c" from this tag <IfModule>