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

Link to comment
https://forums.phpfreaks.com/topic/269299-confused-about-pretty-urls/
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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.