Redirect Wordpress-built site via .htaccess while excluding root url, wp-admin dir, and wp-login.php

Jon

I need to redirect any bridges.edu URLs to losangeles.bridges.edu EXCEPT for the www.bridges.edu itself, the wp-admin directory, and wp-login.php. The first objective (site redirect save for www.bridges.edu) works fine with following coding:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?bridges\.edu$ [NC]
RewriteRule ^.+$ http://losangeles.bridges.edu%{REQUEST_URI} [L,R=301]

However, when I try to exclude the wordpress directories and login, I either get a 500 error using something like the following:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [L]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$ [L]
RewriteCond %{HTTP_HOST} ^(www\.)?bridges\.edu$ [NC]
RewriteRule ^.+$ http://losangeles.bridges.edu%{REQUEST_URI} [L,R=301]

Or I essentially get page not found/server unavailable error as it tries to resolve to non-existent /wp-admin or wp-login.php locations on losangeles.bridges.edu using something like this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^(.*)?wp-login\.php(.*)$
RewriteCond %{REQUEST_URI} !^(.*)?wp-admin$
RewriteCond %{HTTP_HOST} ^(www\.)?bridges\.edu$ [NC]
RewriteRule ^.+$ http://losangeles.bridges.edu%{REQUEST_URI} [L,R=301]

I've tried several other iterations of the preceding based on a bunch of posts I've found here and on other sites, but I can't quite get it to work.

And apologies if I'm missing something simple; I'm an editor with a decent amount of coding knowledge, but I'm certainly not a developer! (Also, my first post here -- sorry if I've misformatted something. I was sure to look through as many similar posts as possible before creating this one.)

Amit Verma

You can use the following :

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?bridges\.edu$ [NC]
RewriteCond %{REQUEST_URI} !wp-admin [NC]
RewriteCond %{REQUEST_URI} !wp-login\.php [NC]
RewriteRule ^.+$ http://losangeles.bridges.edu%{REQUEST_URI} [L,R=301]

Make sure to clear your browser caches before checking this redirect.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

.htaccess redirect /subpage/ to /subpage?/wp-login

Wordpress wp-admin redirect loop, yet again

Nginx giving 404 error for WordPress' /wp-admin/ root

using wp_redirect to redirect wordpress pages

disable wp-admin to wp-login canonical redirect (wordpress)

Stop WooCommerce redirecting wp-login.php and wp-admin to account pages

Change wordpress wp-admin login title

How to find Wordpress Login page. /wp-admin | /wp-login etc does not work

functions.php with wp_redirect($url); exit(); makes wordpress site blank

Wordpress: Login for Users Without access to wp-admin

rename url "localhost/wp-admin" for dashboard in wordpress

Wordpress always redirects to /wp-login.php

Wordpress redirecting to wp-admin/install.php incorrectly

htaccess redirect url from file to root dir

How to get the site root URL when using Wordpress gutenberg wp object

Wordpress - change wp_redirect url to dynamic link

wp-admin on redirect loop

How to redirect Incorrect login details used with wp_login_url?

How to 301 redirect URL with PHP parameters to root DIR in .htaccess?

Wordpress: WP admin not reflecting changes

WordPress infinite redirect loop when accessing wp-admin

Force https to http redirect except for Wordpress /wp-admin directory

Wordpress! 403 Error message and redirect to wp-admin page

Multi-site wordpress redirect between https subdomains via htaccess

Disabling wordpress wp-login.php

WordPress ENV / WP_HOME / WP_SITE_URL

Wordpress wp-admin dashboard

redirect site excluding wp-admin when redirecting each page with individual 301's

wp-login.php redirects to server site, not locahost