943,644 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2821
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 16th, 2009
0

Rewriting .htaccess from a php file or form

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
wickedsunny is offline Offline
96 posts
since Oct 2008
Jan 16th, 2009
0

Re: Rewriting .htaccess from a php file or form

Try:
php Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Jan 16th, 2009
0

Re: Rewriting .htaccess from a php file or form

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
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
wickedsunny is offline Offline
96 posts
since Oct 2008
Jan 16th, 2009
0

Re: Rewriting .htaccess from a php file or form

btw is it possible to write it in this manner ? www.blastingart.com/newfeatures.html ??
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
wickedsunny is offline Offline
96 posts
since Oct 2008
Jan 16th, 2009
1

Re: Rewriting .htaccess from a php file or form

Basically something like
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Jan 16th, 2009
0

Re: Rewriting .htaccess from a php file or form

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
PHP Syntax (Toggle Plain Text)
  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:

PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
wickedsunny is offline Offline
96 posts
since Oct 2008
Jan 16th, 2009
0

Re: Rewriting .htaccess from a php file or form

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
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Jan 16th, 2009
0

Re: Rewriting .htaccess from a php file or form

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!!!
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
wickedsunny is offline Offline
96 posts
since Oct 2008
Jan 16th, 2009
0

Re: Rewriting .htaccess from a php file or form

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
Quote 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.
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Jan 17th, 2009
0

Re: Rewriting .htaccess from a php file or form

If you do rewrite from php
does the .htaccess file have to be chmod 777 ?
does that pose a security risk ?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
juustout is offline Offline
3 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Simple Value Question
Next Thread in PHP Forum Timeline: Send SMS using PHP : Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC