简体   繁体   English

将特定网址重定向到首页

[英]Redirect specific url to homepage

I am building a React (frontend) with Wordpress (Backend - REST API) website. 我正在用Wordpress(后端-REST API)网站构建一个React(前端)。 My domain is example.com which is going to have my React app (frontend) and on example.com/backend I have the Wordpress installation. 我的域名是example.com,它将具有我的React应用程序(前端),而在example.com/backend上,我具有Wordpress安装。

My problem is: I want to redirect example.com/backend and everything on to example.com except example.com/backend/wp-admin (so i can login). 我的问题是:我想将example.com/backend以及除example.com/backend/wp-admin之外的所有内容都重定向到example.com(这样我才能登录)。 Is that do-able? 那可行吗?

In a sentence: Can u redirect example.com/backend but have example.com/backend/wp-admin working (not redirecting)? 一句话:您可以重定向example.com/backend但可以使example.com/backend/wp-admin运行(不重定向)吗?

I tried lots of reggex in my .htaccess but none would do the trick. 我在.htaccess中尝试了很多reggex,但没有一个可以解决。 RewriteEngine On RewriteCond %{HTTP_HOST} ^fanismahmalat.com/backend$ [NC] RewriteCond %{REQUEST_URI} !^(. )?wp-login.php(. )$ RewriteCond %{REQUEST_URI} !^(. )?wp-admin$ RewriteRule ^(. )$ https://example.com/ [R=301,L]

One way to exclude a URL is to have a rule before the "real" redirect, eg 排除URL的一种方法是在“真实”重定向之前设置规则,例如

RewriteRule ^backend/wp-admin - [L]
RewriteRule ^backend/ https://example.com [R,L]

The first rule will handle the wp-admin case. 第一条规则将处理wp-admin情况。 The second rule will catch anything else starting with backend/ . 第二条规则将捕获所有以backend/开头的内容。


Another solution would be to exclude the specific URL from being rewritten 另一个解决方案是将特定的URL排除在重写之外

RewriteCond %{REQUEST_URI} !^/backend/wp-admin
RewriteRule ^backend/ https://example.com [R,L]

When the .htaccess file is in the backend sub-folder, the rules are almost the same, but the RewriteRule pattern does not include the backend prefix 当.htaccess文件是在backend的子文件夹,这些规则几乎相同,但是RewriteRule模式不包括backend前缀

RewriteCond %{REQUEST_URI} !^/backend/wp-admin
RewriteRule ^ https://example.com [R,L]

or 要么

RewriteRule ^wp-admin - [L]
RewriteRule ^ https://example.com [R,L]

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

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