How to control .htaccess with php or how to input php code inside .htaccess file How to control .htaccess with php or how to input php code inside .htaccess file apache apache

How to control .htaccess with php or how to input php code inside .htaccess file


PHP can not control .htaccess ok, but you also can control that by Write and Rewrite the .htaccess file, I can figure that but I don't think this properly work. But you can try that also,

Made a function and inside that do this:

function edit_hta() {    echo "<IfModule mod_rewrite.c> \r\n\r\n RewriteEngine on \r\n";    require('config2.php'); $getquery=mysql_query("SELECT * FROM menu ORDER BY menu_id DESC"); while($rows=mysql_fetch_assoc($getquery)){$menu_id=$rows['menu_id']; $linkname=$rows['linkname'];echo "\r\n RewriteRule ^".$linkname."/{0,1}$  pagee.php?menu_id=".$menu_id. "[QSA,L] \r\n"; }    echo "\r\n </IfModule>";}

OK, then make form, textarea and submit button

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">      <label>        <textarea name="edit_ht" cols="45" rows="5"><?php echo edit_hta(); ?></textarea>      </label>      <input name="submit" type="submit" value="Edit" />    </form>

Than make php coding inside that page:

$submit = $_POST['submit'];if ($submit) {$edit_ht = file_put_contents('.htaccess', $_POST['edit_ht']);}

I hope that can do well, so the major thing is if you have a lot of pages inside you sql database first you have to create that all than you can see inside your from sheet, all of you links showing inside the textarea like this:

<IfModule mod_rewrite.c>  RewriteEngine on RewriteRule ^asasasa/{0,1}$  pagee.php?menu_id=10[QSA,L]RewriteRule ^zxzxzx/{0,1}$  pagee.php?menu_id=9[QSA,L]RewriteRule ^movie/{0,1}$  pagee.php?menu_id=8[QSA,L]  RewriteRule ^song/{0,1}$  pagee.php?menu_id=7[QSA,L]  RewriteRule ^software/{0,1}$  pagee.php?menu_id=6[QSA,L]  RewriteRule ^home/{0,1}$  pagee.php?menu_id=5[QSA,L] </IfModule>

then you hit Edit button then your .htaccess file will edit, and with this method you can control your .htaccess file.I hope you understand if you don't please give me comment.Thank you.


Try this :

RewriteEngine onRewriteRule ^home/?$ /page.php?menu_id=$1 [QSA,NC,L]RewriteRule ^music/?$ /page.php?menu_id=$2 [QSA,NC,L]RewriteRule ^movie/?$ /page.php?menu_id=$3 [QSA,NC,L] RewriteRule ^link_name4/?$ /page.php?menu_id=$4 [QSA,NC,L]RewriteRule ^link_name5/?$ /page.php?menu_id=$5 [QSA,NC,L] RewriteRule ^link_name6/?$ /page.php?menu_id=$6 [QSA,NC,L] 

Be sure to rename the Path name 4,5,6 to your path name