admin管理员组文章数量:1026645
I'm using WordPress 3.1.3 as a full CMS, installed in the root directory of a domain. I have it setup using the built in options to have a static page as the home page, and then my blog at .
What I would like is to have my single blog posts, category pages, archive pages, and tag pages, and any other blog-related pages have the "prefix" of /blog/
in their link structure. So a post URL would be www.example/blog/post-title
Right now, I only have the category pages working correctly. This was accomplished by adding the following line to my .htacces
file:
RewriteRule ^category/(.+)$ /$1 [R=301,L]
Then, I set the Category Base to "blog" on the Permalinks Settings page in WordPress. This gives category pages the URL of: www.example/blog/category-name
(without removing the category prefix in .htaccess
, they had the URL category/blog/category-name
).
In an attempt to get this working for the other things I want it to work for, I set my Tag Base to "blog." I also made my Custom Permalink Structure: /blog/%postname%
(as suggested by a few threads I've found searching on Google).
These settings give the URLs for the single blog posts, tags pages, and archive pages the URL structure I'm looking for. However, it makes them all lead to 404 errors.
I deleted my .htaccess
file to ensure WordPress was writing to it, and it is. If I remove the /blog/
from the permalink structure, everything works correctly, but I no longer have the URL structure I'm looking for.
I'm at a loss as to what I should do. I keep reading threads and guides saying this is as simple as adding /blog/
to the permalink structure, but so far it hasn't been nearly that simple.
.htaccess
contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I'm using WordPress 3.1.3 as a full CMS, installed in the root directory of a domain. I have it setup using the built in options to have a static page as the home page, and then my blog at http://www.example.com/blog
.
What I would like is to have my single blog posts, category pages, archive pages, and tag pages, and any other blog-related pages have the "prefix" of /blog/
in their link structure. So a post URL would be www.example.com/blog/post-title
Right now, I only have the category pages working correctly. This was accomplished by adding the following line to my .htacces
file:
RewriteRule ^category/(.+)$ http://www.example.com/$1 [R=301,L]
Then, I set the Category Base to "blog" on the Permalinks Settings page in WordPress. This gives category pages the URL of: www.example.com/blog/category-name
(without removing the category prefix in .htaccess
, they had the URL category/blog/category-name
).
In an attempt to get this working for the other things I want it to work for, I set my Tag Base to "blog." I also made my Custom Permalink Structure: /blog/%postname%
(as suggested by a few threads I've found searching on Google).
These settings give the URLs for the single blog posts, tags pages, and archive pages the URL structure I'm looking for. However, it makes them all lead to 404 errors.
I deleted my .htaccess
file to ensure WordPress was writing to it, and it is. If I remove the /blog/
from the permalink structure, everything works correctly, but I no longer have the URL structure I'm looking for.
I'm at a loss as to what I should do. I keep reading threads and guides saying this is as simple as adding /blog/
to the permalink structure, but so far it hasn't been nearly that simple.
.htaccess
contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Share
Improve this question
edited Jun 24, 2022 at 20:41
Stephen Ostermiller
4306 silver badges18 bronze badges
asked Jun 5, 2011 at 0:48
PrestonPreston
3751 gold badge4 silver badges12 bronze badges
1
- As a side note, the permalink shown while editing a post is "wrong". It won't show the final link. – Alexis Wilke Commented Oct 29, 2017 at 22:09
2 Answers
Reset to default 7Go to Settings>Permalinks and add it to the permalink structures
You get 404 errors when you add /blog/
to the custom permalink structure and then also add /blog/
to the category base. It should only be added to one, the custom permalink structure.
If you leave your category base and tag base blank and just add /blog/
to the front of the custom permalink structure to make it look like this /blog/%postname%
- this will get the desired result.
Your pages will look like this: domain.example/pagename/
Your post URL will look like this: domain.example/blog/postname
Your category URL will look like this - domain.example/blog/category/postname
I'm using WordPress 3.1.3 as a full CMS, installed in the root directory of a domain. I have it setup using the built in options to have a static page as the home page, and then my blog at .
What I would like is to have my single blog posts, category pages, archive pages, and tag pages, and any other blog-related pages have the "prefix" of /blog/
in their link structure. So a post URL would be www.example/blog/post-title
Right now, I only have the category pages working correctly. This was accomplished by adding the following line to my .htacces
file:
RewriteRule ^category/(.+)$ /$1 [R=301,L]
Then, I set the Category Base to "blog" on the Permalinks Settings page in WordPress. This gives category pages the URL of: www.example/blog/category-name
(without removing the category prefix in .htaccess
, they had the URL category/blog/category-name
).
In an attempt to get this working for the other things I want it to work for, I set my Tag Base to "blog." I also made my Custom Permalink Structure: /blog/%postname%
(as suggested by a few threads I've found searching on Google).
These settings give the URLs for the single blog posts, tags pages, and archive pages the URL structure I'm looking for. However, it makes them all lead to 404 errors.
I deleted my .htaccess
file to ensure WordPress was writing to it, and it is. If I remove the /blog/
from the permalink structure, everything works correctly, but I no longer have the URL structure I'm looking for.
I'm at a loss as to what I should do. I keep reading threads and guides saying this is as simple as adding /blog/
to the permalink structure, but so far it hasn't been nearly that simple.
.htaccess
contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I'm using WordPress 3.1.3 as a full CMS, installed in the root directory of a domain. I have it setup using the built in options to have a static page as the home page, and then my blog at http://www.example.com/blog
.
What I would like is to have my single blog posts, category pages, archive pages, and tag pages, and any other blog-related pages have the "prefix" of /blog/
in their link structure. So a post URL would be www.example.com/blog/post-title
Right now, I only have the category pages working correctly. This was accomplished by adding the following line to my .htacces
file:
RewriteRule ^category/(.+)$ http://www.example.com/$1 [R=301,L]
Then, I set the Category Base to "blog" on the Permalinks Settings page in WordPress. This gives category pages the URL of: www.example.com/blog/category-name
(without removing the category prefix in .htaccess
, they had the URL category/blog/category-name
).
In an attempt to get this working for the other things I want it to work for, I set my Tag Base to "blog." I also made my Custom Permalink Structure: /blog/%postname%
(as suggested by a few threads I've found searching on Google).
These settings give the URLs for the single blog posts, tags pages, and archive pages the URL structure I'm looking for. However, it makes them all lead to 404 errors.
I deleted my .htaccess
file to ensure WordPress was writing to it, and it is. If I remove the /blog/
from the permalink structure, everything works correctly, but I no longer have the URL structure I'm looking for.
I'm at a loss as to what I should do. I keep reading threads and guides saying this is as simple as adding /blog/
to the permalink structure, but so far it hasn't been nearly that simple.
.htaccess
contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Share
Improve this question
edited Jun 24, 2022 at 20:41
Stephen Ostermiller
4306 silver badges18 bronze badges
asked Jun 5, 2011 at 0:48
PrestonPreston
3751 gold badge4 silver badges12 bronze badges
1
- As a side note, the permalink shown while editing a post is "wrong". It won't show the final link. – Alexis Wilke Commented Oct 29, 2017 at 22:09
2 Answers
Reset to default 7Go to Settings>Permalinks and add it to the permalink structures
You get 404 errors when you add /blog/
to the custom permalink structure and then also add /blog/
to the category base. It should only be added to one, the custom permalink structure.
If you leave your category base and tag base blank and just add /blog/
to the front of the custom permalink structure to make it look like this /blog/%postname%
- this will get the desired result.
Your pages will look like this: domain.example/pagename/
Your post URL will look like this: domain.example/blog/postname
Your category URL will look like this - domain.example/blog/category/postname
本文标签:
版权声明:本文标题:url rewriting - How do I add blog as a prefix to permalink structure for blog posts, tag pages, etc.? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1738528010a1579267.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论