Wordpress As Backend Only

前端 未结 2 959
庸人自扰
庸人自扰 2021-01-26 13:10

So I have fully integrated my wordpress posts into my site, however now I am facing a dilemma... I want my URL\'s to be SEO friendly, for example:

My URL structure for a

2条回答
  •  孤街浪徒
    2021-01-26 13:52

    I'm guessing that you want to use the data in Wordpress to display posts without using Wordpress as a frontend? May I ask why you want to do that? Seems like a lot of work and you may able to simple just put your Wordpress install in a blog directory. Then your other code could run in the web root directory.

    But if you really want to set up permalinks using Wordpress as a backend, you can do the following.

    I'm assuming you're using urls like /blog/blog-post.php?postid=1&type=singlePost

    I think I may be wrong about that though...

    Anyway, you can just copy the default Wordpress .htaccess rules and put it in a directory named blog

    Here is the .htaccess file, but with one change. You need to add RewriteBase /blog/

    # BEGIN WordPress
    
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    
    # END WordPress
    

    Now every url in that looks like /blog/my-article or /blog/category/cooking/how-to-cook will be directed to /blog/index.php

    This means you'd have to move your code from blog-post.php to /blog/index.php

    Now in index.php you can retrieve the actually url using $_SERVER['REQUEST_URI']. So if you visited www.mysite.com/blog/category/cooking/how-to-cook, you'd get /blog/category/cooking/how-to-cook.

    Now you can parse the url to get the article name how-to-cook and use it as the id to grab your posts in wp_posts. This will be saved in post_name column.

提交回复
热议问题