【发布时间】:2015-12-17 16:41:19
【问题描述】:
此类问题之前已在 SO 中提出,但提供的解决方案对我不起作用。 How can I remove this directory/folder from url with htaccess rewrite?
我有一个我继承的多站点 wordpress 安装,它在站点的根目录中有一个 .htaccess 文件。
我需要对像 http:thewebsite.com/jol/blog/author/myles/ 这样的所有 URL 进行全局重定向以转到 http:thewebsite.com/jol/author/myles/
到目前为止,我已经在 .htaccess 文件中尝试过这段代码:
# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# Remove subdirectory of "blog" from URLs
RewriteCond %{THE_REQUEST} \ /blog/
RewriteRule ^blog/(.*)$ /$1 [L,R=301]
还有这段代码:
# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{THE_REQUEST} \ /blog/
RewriteRule ^blog/(.*)$ /$1 [L,R=301]
最后,这段代码:
# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^blog/(.*)$ /$1 [R=301,NC,L]
而且它们都完全不起作用。到目前为止,唯一成功的是单独定位每个 URL 并执行重定向,这是...痛苦的。
任何帮助将不胜感激。
【问题讨论】:
-
模式
^blog/会失败,因为您的网址以jol/开头 -
谢谢!当我现在看到它时,这很有意义。那么我将如何定位“博客”的下一个子目录?
-
试试这个
RewriteRule ^(.*(?=blog/))blog/(.*)$ $1$2 [NC,L,R=301] -
你先生……是我的英雄!
标签: wordpress apache .htaccess mod-rewrite