Take the 2-minute tour ×

I sincerely apologize if this is a duplicate. I've looked at so many threads but none seem to apply specifically to what I'm trying to do.. and for some reason, I just have such a difficult time wrapping my brain around .htaccess rewrite rules!

I purchased a php script and after installing it, I create a new post and it works fine.. except of course, it shows: mydomain.com/post.php?id=7

Want I want is to show the title of the post after the .com/

I know some will advise to use a post id or a date or something, but I'd really prefer it to be written as stated. So the end result would be: mydomain.com/this-is-my-first-post

I then want to be able to correctly call this page. I assume this would all be done in the index.php page (which calls the post.php page)?

I found the line in index.php that currently calls the post and it looks like this:

<a href="post.php?id=<?php echo $theArticle['artId']; ?>"><h1><?php echo $theArticle['title']; ?></h1></a>

Is that also what I would need to update?

Thanks for any assistance. I really have tried but I am just not programming minded and struggling mightily!

share|improve this question
This is too broad as it does not only involve rewriting the url, but also preparing the title to be used in the url and retrieving the right information from the database. You should break the problem down, try to solve the different parts and post back here with more specific questions. –  jeroen Oct 30 '13 at 2:40
If your script is written to take a numeric ID, you can just give it a string title and expect it to work. –  Jon Lin Oct 30 '13 at 2:46
Sorry about that. Please ignore the php part. I'll figure that out if I get the htaccess stuff going. Thanks! –  Marcy Stephens Oct 30 '13 at 3:34
add comment

1 Answer

up vote 1 down vote accepted

Your question is a bit too broad, but if you are willing to compromise, you could change the url to something like:


And then you would only need a rewrite rule and no changes in the database retrieving code.

In that case the rewrite rule would look something like:

RewriteRule ^post/(\d+).*$ /post.php?id=$1
                  ^^^^^ capture the number to be used

You would of course also need to rewrite all links to the required format.

share|improve this answer
Hi Jeroen, Thanks.. I did actually get it to work as you suggested. The php stuff aside (sorry that I didn't break the question up), is it not possible to just have the domain.com/title ? I see sites like upworthy that make that happen. Just curious. Thanks again for the help! –  Marcy Stephens Oct 30 '13 at 3:33
@MarcyStephens You could, but you would have to generate a unique slug / url-title for every post and index on that. You would also have to change the sql to get the right posts. –  jeroen Oct 30 '13 at 13:51
I went ahead and went with this solution. It's as close as I can get and at least that title's up there now. Thanks, jeroen! –  Marcy Stephens Oct 30 '13 at 16:06
add comment

Your Answer


