Hiiz is there a way that i can rewrite .htaccess from a php file? well actually i am using a cms for my site and whenever i make a new page i have to rewrite it in htaccess to make it work and SEO friendly. so i was wondering if there is a way to do it directly by php file instead of downloading .htaccess editing and re uploading it. please let me know if anyone have solution for that thx :)

Try:

<?php
$file=".htaccess";
$fp=fopen($file, "a");
$text ="\r\nRewriteEngine on \r\nRewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]";
fwrite($fp, $text);
fclose($fp);
?>

wow thx tht was a quick response !! ok can u make it a lil easier for me now . if i have a file like this. www.blastingart.com/viewPage.php?ID=New Features

what should be the syntax for this file to make it seo friendly ? in the form type php given above :)
thx in advance

Basically something like

RewriteEngine on 
RewriteRule ([^/\.]+)/?.html$ viewPage.php?ID=$1 [L]

So if you typed
www.blastingart.com/New Features.html
into the url, it would be the same as typing in
www.blastingart.com/viewPage.php?ID=New Features

commented: thanks simmply genius !! +1

ok buddy thx for ur help. but im kinda stuk here !!
i have a form page . and then on php page which takes the data and insert in the database now i have no clue how to get the page name inserted into the.htaccess with that. im gona put up the code now.

Form.php

<form action="pagebuildform.php" method="post" name="send" id="send">
                                          <table width="417" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                              <td width="172" align="right" valign="middle" class="txt-reg-BLACK">Page N:ame:</td>
                                              <td width="245" align="left" valign="middle"><input
															  name="Page" type="text"
															  size="30" /></td>
                                            </tr>
                                            
                                            <tr>
                                              <td width="172" align="right" valign="middle">&nbsp;</td>
                                              <td width="245" align="left" valign="middle"><input name="Submit" type="submit" class="buttons" value="Submit" />
                                              <input name="reset" type="reset" class="buttons" id="reset" value="Reset" /></td>
                                            </tr>
                                        </table>
                                      </form>

phpfile which inserts into database:

require_once( '../inc/header.inc.php' );
$ab=mysql_connect ($db['host'], $db['user'] , $db['passwd'] ) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db['db']); 



$sql="INSERT INTO `PageCompose` (
`Page` ,
`PageWidth` ,
`Desc` ,
`Caption` ,
`Column` ,
`Order` ,
`Func` ,
`Content` ,
`DesignBox` ,
`ColWidth` ,
`Visible` ,
`MinWidth`
)
VALUES ('$_POST[Page]', '960px', 'Simple HTML Block', 'newpage', '1', '2','newpage', 'This is my new page', '1', '60', 'non,memb', '0'
)";

if (!mysql_query($sql,$ab))
  {
  die('Error: ' . mysql_error());
  }
echo "Your Page Successfully Created!!!";

mysql_close($ab)
?>

ok what im stuck at is i want that page name('$_POST[Page]') to be inserted in the .htaccess rewrite as we talked above. so with just one submit hit both things work out. new page is inserted in the db and .htaccess rewrited as well. please help me in it :)
thx in advance

dont get a rewrite rule for every page
get a PAGE rule for the php/mysql form
that generates a set of page names that match each other and the the rewrite tule
all the generated page names should match the existing rule

i have no idea how to do that!! well its like that everytime i generate a new page from the form the .htaccess shud be rewriten by the same page name!!!

All page names should generate from the database
for example

/mysite/generatepage.php?id=somename

/mysite/somename.html

it is a waste of time and effort to not have all the page name generate automatically
the rewrite rule

RewriteEngine on
RewriteRule ([^/\.]+)/?.html$ viewPage.php?ID=$1 [L]

, and taken directly from the manual, does just that.
google how to apache mod_rewrite for other examples
if you have not already set up a standardised naming system for your site,
stop now, set up a system, then write a rewrite rule to match the system

you get

  • sensible sitemap
  • logical urls
  • a tree structure
  • user friendly
  • Search engine friendly

1000s of individual rules will just give you a site you cannot even maintain

If it is beyond your skills to generate that rule,
rt_m, there is an example there that shows full tree structure from a single rewrite rule

ask,
ask again,
until one of the answers makes sense,

once the rules for database creation, and mod_rewrite are set, there will be no need to create more rules

If you do rewrite from php
does the .htaccess file have to be chmod 777 ?
does that pose a security risk ?

hiiz i think u guyz are not following what im trying to say. im using dolphin cms. i made a form which i posted above which inserts a new page entry in the database. and to view that page we automatically get this kind of url

www.blastingart.com/viewPage.php?ID=Page Name

and to make it search engine friendly i have to rewrite it in the .htaccess so it looks like this www.blastingart.com/page Name.html

ok now what i want is to make a system that when i generate a new page through that form it will automatically add the rewrite entry in the .ht access file . is it possible? if yes please help !!!

thx in advance :)
regards

Yes the rewrite rule I left earlier will make the id value appear to be the html file. So if you typed
www.blastingart.com/New Features.html into the url, it would be parsed by the server as www.blastingart.com/viewPage.php?ID=New Features

hiiz i think u guyz are not following what im trying to say. im using dolphin cms. i made a form which i posted above which inserts a new page entry in the database. and to view that page we automatically get this kind of url

www.blastingart.com/viewPage.php?ID=Page Name

and to make it search engine friendly i have to rewrite it in the .htaccess so it looks like this www.blastingart.com/page Name.html

ok now what i want is to make a system that when i generate a new page through that form it will automatically add the rewrite entry in the .ht access file . is it possible? if yes please help !!!

thx in advance :)
regards

Yes the rewrite rule I left earlier will make the id value appear to be the html file. So if you typed
www.blastingart.com/New Features.html into the url, it would be parsed by the server as www.blastingart.com/viewPage.php?ID=New Features

Thats what everyone is trying to explain
1 system for creating filenames
1 rule to translate the url between ?=something
and domain/something.html

a rule for every file does not work

that is wht im saying i dono hwo to do it. can anyone help me out ?

Every post, almost, has explained what to do

  • Establish a convention for naming the files from your cms
  • establish a rewrite rule that matches the naming system used

done
Nobody can do it for you, and have tried to explain the process
dont know the names used already
but the thing to do is Stop
until you read the manual and understand it on rewrite, everything you do will make it harder to undo.

thank u :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.