What's the secret wordpress' sitename.com/post-name type permalinks

There Wordpress

may be URLs such as sitename.com/post-title

, although there is no directory named post-name

.

My guess is that index.php

(or maybe 404 page

) should handle such requests.

Someone please explain the exact trick behind this ...

+3


source to share


3 answers


Read about mod override models in this page . This is an Apache module that allows you to parse the content of a request and redirect it to a "real" page without changing the browser address.

Let's say you have this:

 RewriteRule ^post/([0-9]+)?/?([0-9]+)?/?$ /index.php?p=$1&page=$2 [QSA]

      

With this rewrite rule, the request address looks like this:

www.mysite.com/post/10/2

      



Will be redirected to:

www.mysite.com/index.php?p=10&page=2

      

And it is better in terms of Search Engine Optimization aesthetics .

To be specific, in WordPress, every request is redirected to the index.php page, which contains an internal request "parser" that loads content based on the result of the parsing.

नमस्ते!

+4


source


My guess is that index.php should handle this kind of request.

Quite right.



They redirect all requests to index.php via .htaccess rules. If you are thinking about making your decision in your own application, then don't. There are better implementations of this technique today. Here's an example.

+2


source


How it works:

mod_rewrite accepts requests that match a specific parameter and can redirect them to other locations. In the case of wordpress, the entire response (*) is received and passed to the index.php page with a standard router that shares the url i.e. $ _SERVER ["REQUEST_URI"], and maps it to the saved url config and loads the correct component (category, title, page, etc.)

+1


source







All Articles