Rewriting .htaccess from a php file or form

Reply

Join Date: Oct 2008
Posts: 89
Reputation: wickedsunny is an unknown quantity at this point 
Solved Threads: 4
wickedsunny wickedsunny is offline Offline
Junior Poster in Training

Rewriting .htaccess from a php file or form

 
0
  #1
Jan 16th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Rewriting .htaccess from a php file or form

 
0
  #2
Jan 16th, 2009
Try:
  1. <?php
  2. $file=".htaccess";
  3. $fp=fopen($file, "a");
  4. $text ="\r\nRewriteEngine on \r\nRewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]";
  5. fwrite($fp, $text);
  6. fclose($fp);
  7. ?>
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: wickedsunny is an unknown quantity at this point 
Solved Threads: 4
wickedsunny wickedsunny is offline Offline
Junior Poster in Training

Re: Rewriting .htaccess from a php file or form

 
0
  #3
Jan 16th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: wickedsunny is an unknown quantity at this point 
Solved Threads: 4
wickedsunny wickedsunny is offline Offline
Junior Poster in Training

Re: Rewriting .htaccess from a php file or form

 
0
  #4
Jan 16th, 2009
btw is it possible to write it in this manner ? www.blastingart.com/newfeatures.html ??
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: Rewriting .htaccess from a php file or form

 
1
  #5
Jan 16th, 2009
Basically something like
  1. RewriteEngine on
  2. 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
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: wickedsunny is an unknown quantity at this point 
Solved Threads: 4
wickedsunny wickedsunny is offline Offline
Junior Poster in Training

Re: Rewriting .htaccess from a php file or form

 
0
  #6
Jan 16th, 2009
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
  1. <form action="pagebuildform.php" method="post" name="send" id="send">
  2. <table width="417" border="0" cellspacing="0" cellpadding="0">
  3. <tr>
  4. <td width="172" align="right" valign="middle" class="txt-reg-BLACK">Page N:ame:</td>
  5. <td width="245" align="left" valign="middle"><input
  6. name="Page" type="text"
  7. size="30" /></td>
  8. </tr>
  9.  
  10. <tr>
  11. <td width="172" align="right" valign="middle">&nbsp;</td>
  12. <td width="245" align="left" valign="middle"><input name="Submit" type="submit" class="buttons" value="Submit" />
  13. <input name="reset" type="reset" class="buttons" id="reset" value="Reset" /></td>
  14. </tr>
  15. </table>
  16. </form>


phpfile which inserts into database:

  1. require_once( '../inc/header.inc.php' );
  2. $ab=mysql_connect ($db['host'], $db['user'] , $db['passwd'] ) or die ('I cannot connect to the database because: ' . mysql_error());
  3. mysql_select_db ($db['db']);
  4.  
  5.  
  6.  
  7. $sql="INSERT INTO `PageCompose` (
  8. `Page` ,
  9. `PageWidth` ,
  10. `Desc` ,
  11. `Caption` ,
  12. `Column` ,
  13. `Order` ,
  14. `Func` ,
  15. `Content` ,
  16. `DesignBox` ,
  17. `ColWidth` ,
  18. `Visible` ,
  19. `MinWidth`
  20. )
  21. VALUES ('$_POST[Page]', '960px', 'Simple HTML Block', 'newpage', '1', '2','newpage', 'This is my new page', '1', '60', 'non,memb', '0'
  22. )";
  23.  
  24. if (!mysql_query($sql,$ab))
  25. {
  26. die('Error: ' . mysql_error());
  27. }
  28. echo "Your Page Successfully Created!!!";
  29.  
  30. mysql_close($ab)
  31. ?>


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
Last edited by wickedsunny; Jan 16th, 2009 at 7:42 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,358
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 163
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Rewriting .htaccess from a php file or form

 
0
  #7
Jan 16th, 2009
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
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: wickedsunny is an unknown quantity at this point 
Solved Threads: 4
wickedsunny wickedsunny is offline Offline
Junior Poster in Training

Re: Rewriting .htaccess from a php file or form

 
0
  #8
Jan 16th, 2009
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!!!
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,358
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 163
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Rewriting .htaccess from a php file or form

 
0
  #9
Jan 16th, 2009
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
Originally Posted by buddylee
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
Last edited by almostbob; Jan 16th, 2009 at 9:47 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 3
Reputation: juustout is an unknown quantity at this point 
Solved Threads: 1
juustout juustout is offline Offline
Newbie Poster

Re: Rewriting .htaccess from a php file or form

 
0
  #10
Jan 17th, 2009
If you do rewrite from php
does the .htaccess file have to be chmod 777 ?
does that pose a security risk ?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC