1

For a marketing reason, my client needs a standalone HTML Page as the "temporary homepage"

What I would like to do is redirect the homepage to a page OUTSIDE of the WordPress ecosystem - I guess this is done using HTACCESS rules...

Can I even do this without breaking WordPress?

Thanks

1
  • 1
    If you just add index.html to the root of your WordPress installation that should become the homepage. Commented May 13, 2020 at 6:10

2 Answers 2

1

As @JacobPeattie suggested in comments:

If you just add index.html to the root of your WordPress installation that should become the homepage.

This does, however, require that the DirectoryIndex is set appropriately. For example:

DirectoryIndex index.html

The DirectoryIndex is the document that Apache tries to serve when you request a directory. In this case, the document root. Specifying a relative URL-path will look for that file relative to the directory being requested.

Or, to have multiple directory index documents (that are tried in turn):

DirectoryIndex index.html index.php

(index.php would ordinarily be required for WordPress.)

You can change index.html to anything you like.

You can also specify a file in a specific location elsewhere on the filesystem (providing it is publicly accessible). For example:

DirectoryIndex /path/to/alternative/homepage.php

But this will mean that if you request /path/to/any-directory/ then it will also serve /path/to/alternative/homepage.php (via an internal subrequest).

The default WordPress front-controller (directives in .htaccess) don't do anything when you request the homepage (or any directory for that matter). It relies on mod_dir (ie. DirectoryIndex) to make the internal subrequest for index.php. Only when you request /<something> might the request be manually rewritten to index.php.


Alternately, you can use mod_rewrite, before the WordPress front-controller to internally rewrite the request for the homepage (/) to your alternative homepage.

For example:

# Internal rewrite to alternative homepage
RewriteRule ^$ /path/to/alternative/homepage.php [L]

# BEGIN WordPress
# : (WordPress front-controller goes here)

If you did literally want to "redirect" to a temporary homepage then you just need to add the R flag to the above directive. (Although the internal rewrite/subrequest, as mention above, would be preferable in most scenarios.)

For example:

# External "redirect" to alternative homepage
RewriteRule ^$ /path/to/alternative/homepage.php [R,L]

# BEGIN WordPress
# : (WordPress front-controller goes here)

Note that this is a 302 (temporary) redirect.

1
  • 1
    For me, option with [R,L] solved my needs. RewriteRule ^$ https://www.mywpwebsite.com/institutional [R,L] Thus, only the home page is redirected, all other pages remain unchanged. Thanks!
    – MMJ
    Commented Aug 13, 2021 at 13:17
0

If you want to redirect the one page to another page then it is possible with the .htaccess file, add the below rule in the .htaccess:

Redirect 301 https://example1.com/ https://example2.com/

Don't forget to change the example URLs.

1
  • The mod_alias Redirect directive matches against a root-relative (starting with a slash) URL - not an absolute URL - so the above directive will fail to do anything. However, the Redirect directive is also prefix-matching, so this would redirect everything, not just the homepage! (But I don't believe the OP mentioned anything about redirecting to another domain?)
    – MrWhite
    Commented May 14, 2020 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.