问题
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 blog post is:
blog-post.php?postid=1&type=singlePost
I would like the URL to read as the following:
/blog/Title-Of-Article/
Of course "Title-Of-Article" would be dynamic. So how can I accomplish this. I am a fairly new coder and .htaccess is still pretty foreign to me.
I really need help with this, I have scoured the internet looking for solutions and have yet to see anything of use but I could just be not looking for the right thing. Thank you to anyone who has a solution to my problem.
Sorry if I wasn't clear enough, this is my first time posting here on stackoverflow. I only use wordpress as a backend admin for a blog section on my site that I have coded. I have everything integrated and working but I need to figure out how to use SEO friendly URLS on my dynamic php address:
www.mysite.com/blog-post.php?postid=1&type=singlePost
(notice how this file is in the base folder, NOT IN /blog/)
I want it to look like this:
www.mysite.com/blog/Title-Of-Article/
Let me know what to do, Thanks
回答1:
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
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# 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.
回答2:
You dont need to touch htaccess. Just go to settings » permanent links and change default url structure for, lets say, post mame.
来源:https://stackoverflow.com/questions/21612401/wordpress-as-backend-only