-1

I'm sorry if there is already a question on this I just couldn't find it since I don't know what it is called.

Basically, I want to be able to access certain posts using their id without using GET. For example, I would like to access a post using website.com/post/crazy-clickbait-post instead of something like website.com/post.php?id=crazy-clickbait-post. It's just more user-friendly from an advertising perspective.

How would I go about this? I was thinking that maybe there would be a way to use a main post page in the post folder called something like index.php and then that would parse the url to get the post id but I'm not sure if that's possible.

RBT
  • 24,161
  • 21
  • 159
  • 240
vedi0boy
  • 1,030
  • 4
  • 11
  • 32
  • What do you actually mean by "the posts"? That expression does not really make any sense. What you are interested in is a value. It is completely irrelevant where you get it from: GET parameters to a URL, post fields in a request or parts of the URL path component. – arkascha Jan 02 '17 at 14:47
  • If you're using a framework, you'd set up a route. Otherwise you'd utilize rewrite rules in an htaccess file. – noahnu Jan 02 '17 at 14:47
  • 1
    Possible duplicate of [SEO Friendly URL](http://stackoverflow.com/questions/6002203/seo-friendly-url) – Kilian Stinson Jan 02 '17 at 14:48
  • Seriously, if it's a duplicate, just mark it as a duplicate, I don't need the downvote. I specifically mentioned in my question that there is most likely a duplicate out there, I just couldn't figure out the google query for it. I would have never thought to search SEO friendly url. Thanks to those who were nice. – vedi0boy Jan 02 '17 at 14:54

1 Answers1

1

You basically want 'SEO friendly' URLs like the following topic:

How to write htaccess rewrite rule for seo friendly url

In your case you need to add this (or create) to your .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([^/]+)$ /post.php?id=$1 [L]
Community
  • 1
  • 1
Farkie
  • 3,307
  • 2
  • 22
  • 33
  • This does not answer the question, but gives an introduction into the topic of rewriting and GET parameters. The question is about post requests. – arkascha Jan 02 '17 at 14:48
  • Will this redirect the user to another url with the GET info, or will the url stay the same? I'd prefer if it stayed the same in case they want to copy it to share it. – vedi0boy Jan 02 '17 at 14:48
  • That is a standard rewrite rule which works server internally. No http header for redirection is sent. That means the URL visible in the browser stays the same. – arkascha Jan 02 '17 at 14:51
  • Perfect, this is the solution to my problem then, thank you Farkie. – vedi0boy Jan 02 '17 at 14:52
  • @arkascha I think you are getting incorrectly stuck on the GET / POST thing, I don't think the OP was talking about HTTP Verbs. – Farkie Jan 02 '17 at 15:00