简体   繁体   English

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

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

This type of question has been asked in SO before but the offered solutions do not work for me. 之前已经在SO中提出过此类问题,但提供的解决方案对我不起作用。 How can I remove this directory/folder from url with htaccess rewrite? 如何使用htaccess重写从url中删除此目录/文件夹?

I have a multi site wordpress install that I have inherited and it has a single .htaccess file in the root directory of the site. 我有一个已继承的多站点wordpress安装,并且在站点的根目录中有一个.htaccess文件。

I need to do a global redirect on all URLs like this http:thewebsite.com/jol/blog/author/myles/ to go to http:thewebsite.com/jol/author/myles/ 我需要对所有URL进行全局重定向,例如http:thewebsite.com/jol/blog/author/myles/以转到http:thewebsite.com/jol/author/myles/

So far I have tried this code in the .htaccess file: 到目前为止,我已经在.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]

and this code: 和此代码:

# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{THE_REQUEST} \ /blog/
RewriteRule ^blog/(.*)$ /$1 [L,R=301]

and lastly, this code: 最后,这段代码:

# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^blog/(.*)$ /$1 [R=301,NC,L]

and absolutely none of them work at all. 绝对没有人在所有的工作。 The only thing that has been successful so far is targeting each URL individually and performing a redirect, which is...PAINFUL. 到目前为止,唯一成功的方法是分别定位每个URL并执行重定向,即... PAINFUL。

Any help would be hugely appreciated. 任何帮助将不胜感激。

The rules which you tried were not working because you had had: ^blog/ in your patterns. 您尝试的规则不起作用,因为您的模式中包含^blog/ Since the URLs you wanted to rewrite are of the form jol/blog/... , the rule should be updated. 由于您要重写的URL格式为jol/blog/... ,因此应更新规则。

Assuming that jol may vary; 假设jol可能有所不同; use the rule: 使用规则:

RewriteRule ^(.+/(?=blog/))blog/(.*)$ $1$2 [R=301,L,NC]

and if jol will always be in the rules, just use that: 如果jol将始终存在于规则中,则只需使用:

RewriteRule ^jol/blog/(.*)$ jol/$1 [R=301,L,NC]

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

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