Jump to content

Confused About Pretty Urls


robolist

Recommended Posts

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 by robolist
Link to comment
Share on other sites

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 by premiso
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.