I need to redirect a whole WordPress site to a single WordPress page.
A sort of maintenance mode, but the redirect has to go to a published WordPress page. Unfortunately, the maintenance page I need to show has to use other WordPress plugins.
I am not aware of any Maintenance Mode plugin which lets you do this. At most, they let you write custom HTML/CSS code.
I was thinking about a .htaccess mod_rewrite rule. However, I am very weak with mod_rewrite.
First, I disabled canonical redirects.
Then, I tried to use:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/index.php?page_id=813$
RewriteRule ^(.*)$ /index.php?page_id=813 [R=307,L]
However, these rules generate redirect loops. page_id=813
is the ID of my maintenance page, of course.
Is anybody aware of a maintenance mode plugin, which redirects to a published page?
Alternatively, can somebody help me to fix the mod_rewrite rules? Extra cheers if we can leave /wp-admin
out of the redirect rules.
You can actually do this from inside WordPress itself, instead of needing to come up with a confusing and overengineered .htaccess fix.
We can hook into the
template_redirect
filter, which only fires on the front-end (not in wp-admin). We then use theis_page()
function to check if we’re viewing a page with the ID of 813. If not, redirect to that page using thewp_redirect()
function.This will work great for a maintenance mode, as the redirect is made with the 302 ‘temporary’ HTTP header, letting bots and search engines know that your site will be up soon. However, if you’re permanently moving the site, you might want to use a 301 ‘permanent’ HTTP header for the redirect. You can do this by adding a second parameter to the
wp_redirect
function. Example:I have embedded the accepted answer by @shea in a one-file plugin, and added two options: redirect only non-admin users & redirect to an arbitrary URL.
If interested, please feel free to download the plugin from Github => https://github.com/Idearia/wp-redirect-website-to-url.
Options
The plugin options are very simple; for the time being, they are hard-coded in the plugin file, but I might consider building an option page if people request it:
Updated info on the Github page => https://github.com/Idearia/wp-redirect-website-to-url.
Please note that the plugin is very basic; more advanced users might consider instead one of the many maintenance plugins available on the WordPress.org plugin repository.
Let me know if you have any problem running the plugin ð
I’d go for a much simpler solution. My assumption is that you only want anyone to see one page only – no need for any WP page to be visible – for any request for your domain.
So, why not create an HTML page, style it with some CSS, and put that page in another folder on your hosting platform. Make sure the page looks like you want.
Then just point your domain to that new folder. With most hosting platforms, you can specify the base folder of a domain. So point your domain to that new base folder. No need for complicated htaccess redirects, or WP plugins, or special filters to hook into WP.
Or, you could move all content out of the current domain root folder(s), and put in your simple HTML file in it’s place.
May hosting places also have a ‘global redirect’ for any request to any page on your domain.
Either way would be a simple solution to your needs to only have one page for your entire domain.
If you really want an htaccess solution, use this one:
..replacing with your actual domain.Makes SEO happy also.