简体   繁体   中英

Dynamic directories and files like wordpress

In wordpress there are directories which actually do not exists. like example.com/post/name-of-the-post actually opens a main php file which fetches the content of that posts from database. How can i implement this natively on linux apache php server without wordpress?

You need to use .htaccess . This is the technology behind Wordpress' ability to do what you are wanting to do.

Here are the docs from apache .

Also here's a nice Tutorial

I don't know why people use mod_rewrite, it is overkill for most tasks. For most things there are more nimble modules available. That is not to deny mod_rewrite, it has its place, but I find it is over used. In this particular case you can use mod_alias, no need for mod_rewrite. Eg

AliasMatch ^/post/(.*) /real/path/post.php$1

module docs here: https://httpd.apache.org/docs/2.2/mod/mod_alias.html

This doc beautifully outlines when NOT to use mod_rewrite: http://httpd.apache.org/docs/current/rewrite/avoid.html

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