iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-04-2009, 12:23 PM
WebProWorld New Member
 
Join Date: Sep 2009
Posts: 1
willoTheWisp RepRank 0
Default Database generated URLs and mod-rewrite

Hi,

I'm a newbie to mod_rewrite and .htaccess, but not PHP and MySQL.

I'm creating a website in PHP for a client, and they wish to have what they call 'friendly-URLs'. So naturally I'm using the mod-rewrite module and .htaccess.
My .htaccess lines of code are as follows:

RewriteRule ^/?$ index.php [L]
RewriteRule ^login/?$ login.php [L]
etc.

However, I'm also building a CMS which the user can use to create pages on the site. Each of these pages is stored in the database: the data stored for each page is pageid (auto increment), title, url, content etc.
URL is used so the user can specify what the page is called, so in the browser it will appear as www.example.com/newpage

However, how do I set my .htaccess file up so if the user clicks the link of one of the generated pages (called about-us) for example, it redirects to index.php for example?
index.php would then call to the database for the content of the about-us' page.

Any help will be appreciated!

Willo

Last edited by weegillis; 09-04-2009 at 09:24 PM. Reason: Help member to display intended generic url
Reply With Quote
  #2 (permalink)  
Old 09-05-2009, 03:16 AM
danlefree's Avatar
WebProWorld Pro
 
Join Date: Jun 2005
Location: Seattle
Posts: 269
danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4
Default Re: Database generated URLs and mod-rewrite

Here's how I'd do it:

Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/login/ [NC]
RewriteRule . /index.php?title=$1 [L,QSA]
  • RewriteCond %{REQUEST_FILENAME} !-f - Apply if requested URI is not an existing file
  • RewriteCond %{REQUEST_FILENAME} !-d - Apply if requested URI is not an existing directory
  • RewriteCond %{REQUEST_URI} !^/login/ - Apply if requested URI is not affected by your /login/? rewrite
  • RewriteRule . /index.php?title=$1 - Parse the request through your index.php file with the $_GET['title'] string set (note that the QSA/Query String Append directive must be specified - otherwise all requests will be passed to /index.php without the $_GET['title'] string)
__________________
Dan LeFree | Product Manager (Linux VPS Hosting) | Owner/Operator (Web development, marketing)

Last edited by danlefree; 09-05-2009 at 03:18 AM. Reason: ! == not
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
rewrite URLs with HT Access pagetta Web Programming Discussion Forum 12 09-06-2007 02:01 AM
Redirecting database generated pages from within .htaccess LoveNotWar Web Programming Discussion Forum 4 01-04-2007 02:01 AM
Database generated dropdown menu supernatural_247 Web Programming Discussion Forum 3 05-26-2005 09:40 PM
Ads generated on a PHP generated page? Kris@NP.com Google AdWords/Google AdSense 6 08-19-2004 08:00 PM


All times are GMT -4. The time now is 04:27 AM.



Search Engine Optimization by vBSEO 3.3.0