htaccess redirect not redirecting index.html page - wordpress

I have a client project that requires a specific domain name to be redirected to another directory, while the rest of the site is a standard WordPress installation.
My redirect appears to be written properly, and is placed at the very top of the htaccess file:
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^old_domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old_domain\.com$ [OR]
RewriteRule ^/?$ "http\:\/\/www\.new_domain\.com\/directory\/" [R=301,L]
The problem is that it won't redirect http://old_domain.com/index.html
Instead, it sends the user to WP's 404 page.
What am I doing wrong?
UPDATE:
After receiving an otherwise helpful suggestion, I thought some additional context would be in order.
This is a real estate project. The main WP site (new_domain.com) is for condo sales, and they have a separate external site for condo rentals.
They have a third legacy domain (old_domain.com) that they want to redirect to a portal page (new_domain.com/directory), where the user can select buy or rent, and then proceed to the appropriate site.
So, we don't want all requests to be redirected, just any that use the legacy domain.

The following rule should work. It should redirect all requests from www.old_domain.com and http://old_domain.com to http://www.new_domain.com/directory
RewriteEngine On
RewriteRule ^(.*)$ http://www.new_domain.com/directory/$1 [R=302, L]
Change 302 to 301 when you are sure the redirect works
EDIT:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old_domian.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old_domain.com$
RewriteRule (.*)$ http://www.new_domain.com/directory/$1 [R=302,L]

You must have RewriteEngine On. You can consolidate the two www. and non-www. tests. Don't put an [OR] after the last RewriteCond.
RewriteCond %{HTTP_HOST} ^(www\.)?old_domain\.com$
Is new_domain.com an "add-on" to old_domain.com, so that both pass through the same .htaccess file, but with different domain names? Or are these physically separate systems, with their own .htaccess files? That is, what URLs are going to pass through this .htaccess file?
Your current code will redirect anything coming in on old_domain.com to /directory/<original URI+Query String> on new_domain.com, and tell search engines and users to update their entries and bookmarks. Is that what you want?

Related

Redirecting .com to .com.au breaks .com.au with too many redirects, also using change to naked domain from www. using htaccess

my domain breaktagdigital.com needs to be redirected to https://breaktagdigital.com.au I already have this setup in my rewrite rules which does not seem to be redirecting the URL or any other pages, which it is also not allowing me to do within wordpress, force secure is on within cloudflare and I just turned it off in Ithemes:
RewriteCond %{HTTP_HOST} ^www.breaktagdigital.com.au [NC]
RewriteCond %{HTTP_HOST} ^breaktagdigital.com [NC]
RewriteRule ^(.*)$ https://breaktagdigital.com.au/$1 [L,R=301,NC]
if I add anything to this to try redirect breaktagdigital.com any further it breaks .com.au help please?
Should I be putting another if module in between wordpress and ithemes??
Based on your shown samples, could you please try following. This will redirect from www/non-www yoursite.com TO yoursite.com.au site. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)(breaktagdigital\.com) [NC]
RewriteRule ^ https://%1.au%{REQUEST_URI} [L,R=301,NE]

Restricting public access to entire WP website

I plan on having my website undergo scheduled maintenance, and simply want to restrict any access to the site or its subpages unless its coming from my IP. I would like to redirect anyone else to a temporary page instead.
I've seen the modifying the htaccess like:
order deny,allow
deny from all
allow from 98.6.000.111
But 1) this doesn't allow me to temporarily redirect users to another HTML page and 2) speaking of temporarily, in my experience users have had their browsers cache the htaccess and even after I change it, they were still being redirected and this is obviously undesirable.
Are there any other strategies, or ways to prevent the issues mentioned above with the htaccess method?
Note: I am not using a plugin for this as the site is undergoing massive changes including swapping of plugins/code/etc so I need the redirect to be more higher-level than WP-level stuff.
You can use a 302 temporary redirect:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^98.6.000.111
RewriteRule .* http://www.anothersite.com [R=302,L]
or (you almost got it right)
ErrorDocument 403 http://www.anothersite.com
Order deny,allow
Deny from all
Allow from 98.6.000.111
The last option has some caveats depending on your WordPress folder structure.
In the case of redirecting to subdomain you can do:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^98.6.000.111
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteCond %{REQUEST_URI} !^/yoursubdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yoursubdirectory/$1
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteRule ^(/)?$ yoursubdirectory/index.html [R=302,L]
Explanation:
The 1st line enables Apache’s rewrite engine, mod_rewrite.
The 2nd line checks if the request is coming from your IP. If it is, then the redirect does not happen.
The 3rd line takes makes sure requests to http/https and www/non-www are used.
The 4th line prevents an infinite-loop scenario by testing the request against the name of your subdirectory.
The last line basically redirects all requests that meet all previous rewrite conditions to the specified subdirectory and file.

How to redirect a WordPress site to a new domain using .htaccess EXCEPT specific pages

My company has moved our primary domain from architectsmarketing.com to archmarketing.org, and recreated many of the pages using the same WordPress page structure with a new WordPress theme.
However, some of the pages are rather complicated, and depend on the functionality of the old theme, so we'd prefer to leave these pages for now on the old site.
We're using .htaccess to do a 301 Redirect for the site, which works nicely:
RewriteEngine on
RewriteBase /
RewriteRule (.*) http://archmarketing.org/$1 [R=301,L]
Since we want to be able to access the back end, I added a condition:
RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-login|wp-content|wp-includes|dap) [NC]
To access site pages normally (without redirects) for comparison with the new site, I sometimes add a condition to exclude my specific IP address, which works perfectly:
RewriteCond %{REMOTE_HOST} !^73.222.196.53
The tricky part is when I try to keep SOME of the WordPress pages still going to the original site. For example, here is a page URL that I want to access on the old site:
http://architectsmarketing.com/petrie-method/optin-1/
I've tried using the following condition:
RewriteCond %{REQUEST_URI} !^/(petrie-method).*$
This does match the page and exclude it from the RewriteRule, but it doesn't allow the page URL to be resolved properly. Instead, that URL redirects to the root of the new site.
So to sum up, my current code (without the IP exclusion) that doesn't quite work is:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-login|wp-content|wp-includes|dap) [NC]
RewriteCond %{REQUEST_URI} !^/(petrie-method).*$
RewriteRule (.*) http://archmarketing.org/$1 [R=301,L]
NOTE: This all goes above the standard WordPress Rewrite block.
I would greatly appreciate any assistance. I have been researching .htaccess rules for hours, and tried dozens of code combinations without success.

Redirect Main Site to Subsite in Multisite Wordpress

I have multi-site wordpress, I want to redirect the main site to one of the sub-site but redirection in .htacecss gives error. Is there any way to redirect a main site to its sub-site. That looks not possible but I am not a wordpress expert so just verifying.
The redirect should be like
redirect 301 link
Or if there is any other way to do that?
The Redirect directive doesn't take the hostname as part of the URI path (in your case the second argument). You'll need to match that against the %{HTTP_HOST} variable using mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/main-site/sub-site
RewriteRule ^/?main-site(.*)$ /main-site/sub-site$1 [L,R=301]
You'll want to put these above any rules you may already have in your htaccess file.

.Htaccess help new file on server?

Hi what does this code do, I have a seo company doing some work on my site, and just noticed this being on my server. thanks
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]
If users try to access http://mydomain.com/ they will be redirected to http://www.mydomain.com/.
This is useful to avoid Duplicate Content, which search engines don't like. So it's basic SEO.
Duplicate Content means that the Content of a website is accessible at more than one URL, in your case http://mydomain.com/ and http://www.mydomain.com/. The RewriteRule kills the URL without www.

Resources