简体   繁体   中英

htaccess Friendly Urls Rewrite

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!

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

mydomain.com/post/7/the-title-of-post-7

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM