本文介绍了.htaccess重定向与异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将所有访问重定向到特定子文件夹,但有一些例外。
I am trying to redirect all visits to a specific sub-folder with a few exceptions.
这是我尝试重定向的URL:
This is the URL I am trying to redirect:
- www.example.com/my-sub-folder /
我希望对该URL下的任何内容的任何匹配都重定向到以下URL:
I would like any hits to anything under that URL to be redirected to the following URL:
- www.example.com/news / category / my-new-sub-folder /
除了,我不想重定向这些URL:
Except, I don't want to redirect these URLs:
- www.example.com/my-sub-folder/my-special-folder /.*
- www .example.com / my-sub-folder / wp-admin /.*
我已尝试在。 htaccess文件,但似乎无法处理以下异常:
I have tried to do the following within my .htaccess file but it does not seem to deal with the exceptions:
RewriteCond %{REQUEST_URI} !^/my-sub-folder/my-special-folder(/.*)?$ [OR]
RewriteCond %{REQUEST_URI} !^/my-sub-folder/wp-admin(/.*)?$
RewriteCond %{REQUEST_URI} ^/my-sub-folder(/.*)?$
RewriteRule ^(.*)$ /news/category/my-new-sub-folder/ [R=301,L]
什么是我做错了还是有更好的方法?
What am I doing wrong or is there a better way?
谢谢
推荐答案
这是因为您在条件中使用 OR
时需要包括所有条件。试试这个规则。
It's because you are using OR
in the conditions you need to include all the conditions. Try this rule.
RewriteCond %{REQUEST_URI} !^/my-sub-folder/my-special-folder/? [NC]
RewriteCond %{REQUEST_URI} !^/my-sub-folder/wp-admin/? [NC]
RewriteCond %{REQUEST_URI} ^/my-sub-folder/?
RewriteRule ^(.*)$ /news/category/my-new-sub-folder/ [R=301,L]
这篇关于.htaccess重定向与异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!