Jump to content

Trying to Rewrite For Domain.com/Title


MarcyS
Go to solution Solved by requinix,

Recommended Posts

I've been trying for hours to rewrite my current url:

 

domain.com/post.php?id=7

 

...and make it appear like this:

 

domain.com/this-is-my-title

 

I haven't been able to do it yet. All the online examples show using an id first or something, but I really like just .com/title only. 

 

So.. can I do that? I've seen other sites achieve it, such as upworthy, so I know it's possible. 

 

Part II: 

 

How would I call the new page from index.php? I have a database table called 'article' and the column I need is 'title' and there's obviously a postid for each entry.. 

 

I can manage to use php enough to put a dash in between all the words of the title and remove all special characters but... Not sure how to make the call though. I mean... I see that $theArticle['title'] returns the title in my current code, but displaying the url only? 

 

Is what I'm trying possible?  Thanks for any suggestions!

 

 

 

 

Link to comment
Share on other sites

  • Solution

You can't do that directly. Rewriting works by taking pieces of the URL and rearranging them into something you can use with your PHP script. That means all you have to work with (in your example) is "this-is-my-title". You can't conjure up the id=7 from that.

 

However your PHP script can. If you must use "/this-is-my-title" then the simplest course of action is to modify your post.php so that it can take a title as well as/instead of an ID number. /post.php?title=this-is-my-title

Link to comment
Share on other sites

Well at least I won't beat my head against the wall over this anymore. Thanks for letting me know that it can't really be done this way. I modified htaccess to allow for post/id/title.. and that's much better than what it was. 

Thanks for the reply! 

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.