Baving Posted November 29, 2006 Share Posted November 29, 2006 Hello,Is there anyway using PHP and .htaccess to accomplish the following: -I store content of the pages in a database and having a file like 'page.php?p=pagenamehere' to output the page in my view looks silly.Is there anyway I could do like..www.mysite.com/pages/test.htmlWhen typing in a page name after /page/ it will check in the database to see if there is a page which the user entered. If so the page will be displayed. So the files do not have to be stored in the pages folder they are actually grabbed from the database.Thanks Link to comment https://forums.phpfreaks.com/topic/28885-page-grabber/ Share on other sites More sharing options...
bljepp69 Posted November 29, 2006 Share Posted November 29, 2006 Your .htaccess Rewrite Rule would look something like:RewriteRule ^pages/(.*) /page.php?p=$1This tells Apache to use the file page.php with the query string 'p=pagenamehere'. Then you put the proper code in your page.php file to retrieve the file listed in $_GET['p'] Link to comment https://forums.phpfreaks.com/topic/28885-page-grabber/#findComment-132263 Share on other sites More sharing options...
Baving Posted November 29, 2006 Author Share Posted November 29, 2006 This is my page.php script: -[code] if(@$_GET['p']) { $page = security($_GET['p']); $sql = "SELECT * FROM page WHERE id = '". $page ."' LIMIT 1"; $query = mysql_query($sql); if(!$query) { sql_error(mysql_error()); } if(mysql_num_rows($query)==0) { die("Page 404 not found!"); } $page = mysql_fetch_array($query); echo $page['content']; }[/code]When I try and use the .htaccess file I get the following error:-[quote]Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.More information about this error may be available in the server error log.[/quote] Link to comment https://forums.phpfreaks.com/topic/28885-page-grabber/#findComment-132269 Share on other sites More sharing options...
bljepp69 Posted November 29, 2006 Share Posted November 29, 2006 1. You have to make sure your hosting company allows for url rewrites.2. You also need to make sure your .htaccess file includes the following: Options +FollowSymLinks RewriteEngine On (Then do your RewriteRule here)Based on the error you're getting above, it looks like your server is honoring the fact you have an .htaccess file. Any misspelling or bad formats within the .htaccess file can cause this issue, however.There's a good tutorial on here - [url=http://www.phpfreaks.com/tutorials/23/0.php]Search Engine Friendly URLs with mod_rewrite[/url] Link to comment https://forums.phpfreaks.com/topic/28885-page-grabber/#findComment-132273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.