.htaccess redirect directory to a single page

為{幸葍}努か 提交于 2019-12-22 08:16:59

问题


I want to redirect all pages from the .com/blog directory to the .com/error directory.

I have searched the web, and found loads of different ways of doing it, but I want it to redirect to a single page.

All the things I have tried redirect to the same file name, but in different directory. For example, .com/blog/index.nonexisting redirects to .com/error/index.nonexisting.

I would like all files in the first directory to redirect to a certain file, so if you go to .com/blog/whatever.php it would go to .com/error/index.php, and if you go to .com/blog/random.xml you would be redirected to .com/error/index.php.

Is there any way to do this?


回答1:


Try putting this in your .htaccess:

RewriteEngine on
RewriteRule ^blog/(.+) error/index.php [L,R]

Replace R with R=301 if you want a 301 redirect, and get rid of R entirely if you don't want an external redirect.




回答2:


In wordpress I used this for a subdmoain on a multisite.

So "subdomain.domain.org/wp_super_faq/AnyAndAllTextAtAll" will redirect to "subdomain.domain.org/faqs"

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.org [NC]
RewriteRule ^wp_super_faq.*$ https://subdomain\.domain\.org/faqs/ [R=301,L]


来源:https://stackoverflow.com/questions/10642602/htaccess-redirect-directory-to-a-single-page

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