简体   繁体   English

使用.htaccess从WordPress URL中删除目录文件夹

[英]Use .htaccess to remove directory folder from WordPress URL

I want to remove a folder from my WordPress URL in a particular case: 在特定情况下,我想从WordPress URL中删除文件夹:

From: 从:

http://capitulardesign.com.br/blog/portfolio/70-anos-sinduscon/

To: 至:

http://capitulardesign.com.br/portfolio/70-anos-sinduscon/

But the rule must work only on /blog/portfolio/ cases. 但是,该规则仅适用于/blog/portfolio/情况。 The WordPress is installed on /blog/ folder and the normal website (custom PHP pages mixed with WordPress Codex codes) is in the root folder. WordPress安装在/blog/文件夹中,普通网站(混合了WordPress Codex代码的自定义PHP页面)位于根文件夹中。

Plus: The /portfolio/ is a Custom Post Type taxonomy. 加: /portfolio/是自定义帖子类型分类法。

That would be a really, hmmm... ineffective solution. 那将是一个非常糟糕的解决方案。

  1. Have you considered to alter the rewrite_rules and change portfolio "term" link with term_link ? 你有没有考虑改变rewrite_rules与和变化组合“术语”链接term_link

    Check out what current rules of the portfolio using portfolio_rewrite_rules filter and change links to them using term_link filter. 检查出什么现行规则portfolio使用portfolio_rewrite_rules过滤器,并使用改变它们的链接term_link过滤器。

  2. Another way to solve this will be to change with_front (to false ) of your rewrite element of arguments array for taxonomy portfolio (while register_taxonomy ). 解决此问题的另一种方法是将分类组合的arguments数组的rewrite元素的with_front (更改为false )(而register_taxonomy )。

Put the following code in main root .htaccess file : 将以下代码放入主根.htaccess文件中:

RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} !\s/+portfolio/ [NC]
RewriteRule ^blog/portfolio/(.*)$ portfolio/$1 [R=302,L,NE]
RewriteRule ^portfolio/(.*)$ blog/portfolio/$1 [L]

The scenario is to redirect any request for /blog/portfolio/ to /portfolio/ then internally redirect any /portfolio/ to /blog/portfolio/ . 该方案是将对/blog/portfolio/任何请求重定向到/portfolio/然后在内部将任何/portfolio/重定向到/blog/portfolio/

Note: clear your browser cache and test it , if Ok , change 302 to 301 to be permanent redirection 注意:清除浏览器缓存并进行测试,如果确定,将302更改为301以进行永久重定向

use better search replace plugin to replace your url. 使用更好的搜索替换插件来替换您的网址。 old url 旧网址

http://capitulardesign.com.br/blog/portfolio/

New url 新网址

http://capitulardesign.com.br/portfolio/

No need of htaccess 无需htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^capitulardesign.com.br
RewriteRule ^blog/(.*)$ blog/portfolio/$1 [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM