robolist Posted October 10, 2012 Share Posted October 10, 2012 (edited) I'm fairly new to developing sites with dynamically generated pages and have just built my first CMS. Currently all pages come off the index and are pulled from its ID number and their URLs are like this mydomain.com/directory/index.php?subj=1 Its still in production so i only have three pages; Home, Events and Contact. Each one is represented by ID 1, 2 and 3. I have managed to create an .htaccess file and have successfully changed the URL to mydomain.com/directory/1/ (although i think im going to remove that trailing slash). But what i really want to do is pull the page title (except for home which should come off the root) but i just cant seem to get my head around it. If anyone could point me in the right direction I would be very grateful. Basically I need the URL to look something like this mydomain.com/directory/contact At the moment my .htsccess file looks like this RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^([a-zA-Z0-9]+)/$ index.php?subj=$1 Cheers Edited October 10, 2012 by robolist Quote Link to comment Share on other sites More sharing options...
thara Posted October 10, 2012 Share Posted October 10, 2012 Always use right forum to ask question. This should come through 'mod_rewrite' forum. Quote Link to comment Share on other sites More sharing options...
robolist Posted October 10, 2012 Author Share Posted October 10, 2012 Always use right forum to ask question. This should come through 'mod_rewrite' forum. Cheers, I didn't notice there was a 'mod_rewrite' forum. Quote Link to comment Share on other sites More sharing options...
premiso Posted October 10, 2012 Share Posted October 10, 2012 (edited) You will need to make a "slug" type field in your database and or have an array map of title -> id. To grab the title with htaccess: RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^directory/(.*)$ index.php?subj=$1 Then you will just either need to query for a slug and see if it is valid or check an array or something similar in your index file. Edited October 10, 2012 by premiso Quote Link to comment Share on other sites More sharing options...
robolist Posted October 11, 2012 Author Share Posted October 11, 2012 You will need to make a "slug" type field in your database and or have an array map of title -> id. To grab the title with htaccess: It worked a treat, thanks so much. Don't you just hate it when the obvious answer is right in front of you but you just can't see it? haha I should have thought of that in the first place Many thanks for your help Rob Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.