2014-07-27 23:38 阅读 30

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

I am trying to use htaccess to remove the sub directory from the url and leave everything else.

The current links look like this...

I need the links to look like this...

there is an installation of WP at both locations with the same DB (different physical databases)

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dtcwehta624485 dtcwehta624485 2014-07-27 23:43

    How about

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

    This will make every links like:

    behave as if they were:

    And if you want the inverse effect, meaning that all link with /blog/stuff change into /stuff try this instead:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^blog/(.*)$ /$1 [L,R=301]
    点赞 评论 复制链接分享