简体   繁体   English

htaccess重写url以删除/ folder /,但之后保留所有其他内容

[英]htaccess rewrite url to remove the /folder/ but leave everything else after

I am trying to use htaccess to remove the sub directory from the url and leave everything else. 我正在尝试使用htaccess从网址中删除子目录,并保留其他所有内容。

The current links look like this... 当前链接看起来像这样...

http://blog.domain.com/blog/page-title http://blog.domain.com/blog/page-title

I need the links to look like this... 我需要链接看起来像这样...

http://blog.domain.com/page-title http://blog.domain.com/page-title

there is an installation of WP at both locations with the same DB (different physical databases) 在两个位置都安装了具有相同DB(不同物理数据库)的WP

so I have tried this... 所以我已经尝试过了

RewriteEngine On 
RewriteRule ^$ blog/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ blog/$1

and lots of other things, just cant seem to work it out with all the attempts. 和许多其他事情,似乎无法通过所有尝试解决。

Would love a little help on this 希望对此有所帮助

How about 怎么样

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^(.*)$ blog/$1 [L]

This will make every links like: 这将使每个链接都像:

http://blog.domain.com/page-title

behave as if they were: 表现得像是:

http://blog.domain.com/blog/page-title

And if you want the inverse effect, meaning that all link with /blog/stuff change into /stuff try this instead: 而且,如果您想要相反的效果,则意味着所有带有/blog/stuff链接/blog/stuff更改为/stuff尝试以下操作:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^blog/(.*)$ /$1 [L,R=301]

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

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