| | |
Rewriting .htaccess from a php file or form
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2008
Posts: 89
Reputation:
Solved Threads: 4
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 Syntax (Toggle Plain Text)
<?php $file=".htaccess"; $fp=fopen($file, "a"); $text ="\r\nRewriteEngine on \r\nRewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]"; fwrite($fp, $text); fclose($fp); ?>
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
•
•
Join Date: Oct 2008
Posts: 89
Reputation:
Solved Threads: 4
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
what should be the syntax for this file to make it seo friendly ? in the form type php given above
thx in advance
•
•
Join Date: Oct 2008
Posts: 89
Reputation:
Solved Threads: 4
btw is it possible to write it in this manner ? www.blastingart.com/newfeatures.html ??
Basically something like
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
PHP Syntax (Toggle Plain Text)
RewriteEngine on RewriteRule ([^/\.]+)/?.html$ viewPage.php?ID=$1 [L]
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
- Benjamin Franklin
•
•
Join Date: Oct 2008
Posts: 89
Reputation:
Solved Threads: 4
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
phpfile which inserts into database:
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
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)
<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"> </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:
PHP Syntax (Toggle Plain Text)
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
Last edited by wickedsunny; Jan 16th, 2009 at 7:42 pm.
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
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
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
•
•
Join Date: Oct 2008
Posts: 89
Reputation:
Solved Threads: 4
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 , 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
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
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]
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
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
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
![]() |
Similar Threads
- Mod_Rewrite Problem (Linux Servers and Apache)
Other Threads in the PHP Forum
- Previous Thread: Simple Value Question
- Next Thread: Send SMS using PHP : Problem
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select send server sessions sms snippet soap source space speed sql static structure syntax system table tutorial up-to-date update upload url validation validator variable video web wordpress xml youtube






