Apache Conditional RedirectMatch

北城以北 提交于 2020-01-05 04:07:31

问题


I have moved a website from /blog/ to the web root. I created a RedirectMatch 301 for my URLs which I believe is correct:

RewriteEngine On
RewriteBase /
RedirectMatch 301 ^/blog/(.*)$ /$1

This works correctly. Now, domain.tld/blog/foo/ redirects to domain.tld/foo/

However, there is one issue. There is a page on the website with the slug: /blog/

Now you can't access the page since domain.tld/blog/ redirects to domain.tld/

So what I would like to accomplish is not to redirect /blog/, but to redirect /blog/everything/else/

domain.tld/blog/ no redirection

domain.tld/blog/foo/ redirects to domain.tld/foo/

domain.tld/blog/foo/bar/ redirects to domain.tld/foo/bar/ Etc.

Many thanks for your help!


回答1:


Can you try this? I think it needs a little change:

RewriteEngine On
RewriteBase /
RedirectMatch 301 ^/blog/(.+)$ /$1

Remember to clear cache + history on browsers before testing, browsers remember 301 redirect rules.

Hope that helps.



来源:https://stackoverflow.com/questions/34718903/apache-conditional-redirectmatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!