我已将所有内容重定向到另一个域,但我指定的某些地址除外
这无疑是这里的问题。需要将其他HTTP请求添加到以下规则块中,以防止针对example.com
正在重定向到example.dev
.
# URLs that should not be redirected - accessible from both domains
# - Sets TARGET_DOMAIN to empty string (ie. no target domain)
RewriteCond %{REQUEST_URI} ^/login [OR]
RewriteCond %{REQUEST_URI} ^/admin [OR]
RewriteCond %{REQUEST_URI} ^/wp-admin [OR]
RewriteCond %{REQUEST_URI} ^/wp-login [OR]
RewriteCond %{REQUEST_URI} ^/wp-admin [OR]
RewriteCond %{REQUEST_URI} ^/wp-content [OR]
RewriteCond %{REQUEST_URI} ^/wp-includes [OR]
# Add more conditions here...
RewriteCond %{REQUEST_URI} \\.(php|css|js|jpg|gif|webp)$ [OR,NC]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [E=TARGET_DOMAIN]
但是,为了确定要排除的这些附加URL,您需要检查浏览器中发出的HTTP请求。其中一些请求可能由JavaScript/AJAX触发。不幸的是,我不知道这些请求会是什么,但可能会因插件等的不同而有所不同。
或者,您改变方法,而不是重定向;“一切”;从…起example.com
到example.dev
(默认操作)仅重定向选定URL。例如:
一些页面URL重定向到(或保留在)example.com
某些页面的URL重定向到(或保留在)example.dev
任何未指定的URL都不会重定向英寸.htaccess
:
# Prevent rewritten requests (to the WP front-controller) from being redirected
RewriteCond %{ENV:REDIRECT_STATUS} .
RewriteRule ^ - [L]
# The TARGET_DOMAIN environment variable holds the desired target domain (if any)
# - for the requested URL
# eg. "example.com" or "example.dev" or empty for no redirect / accessible from both.
# The "default" is NO REDIRECT
# URLs that should be redirected to (or remain at) example.com
RewriteCond %{REQUEST_URI} ^/bio [OR]
RewriteCond %{REQUEST_URI} ^/computing [OR]
RewriteCond %{REQUEST_URI} ^/contact [OR]
RewriteCond %{REQUEST_URI} ^/donate [OR]
RewriteCond %{REQUEST_URI} ^/encrypt [OR]
RewriteCond %{REQUEST_URI} ^/genderless-pronouns [OR]
RewriteCond %{REQUEST_URI} ^/gnu-linux-controversy [OR]
RewriteCond %{REQUEST_URI} ^/keys [OR]
RewriteCond %{REQUEST_URI} ^/legal [OR]
RewriteCond %{REQUEST_URI} ^/pages [OR]
RewriteCond %{REQUEST_URI} ^/readings [OR]
RewriteCond %{REQUEST_URI} ^/now
RewriteRule ^ - [E=TARGET_DOMAIN:example.com,S=1]
# URLs that should be redirected to (or remain at) example.dev
RewriteCond %{REQUEST_URI} ^/example-one [OR]
RewriteCond %{REQUEST_URI} ^/example-two [OR]
RewriteCond %{REQUEST_URI} ^/example-three
RewriteRule ^ - [E=TARGET_DOMAIN:example.dev]
# Redirect to the desired TARGET_DOMAIN (if any)
# - if not already at the TARGET_DOMAIN
RewriteCond %{ENV:TARGET_DOMAIN} .
RewriteCond %{HTTP_HOST}@@%{ENV:TARGET_DOMAIN} !^([a-z0-9.-]+)@@\\1$
RewriteRule ^ https://%{ENV:TARGET_DOMAIN}%{REQUEST_URI} [R=302,L]
# BEGIN WordPress
# :