Search code examples
.htaccess

.htaccess holding page without changing site URL


If I have a site mysite.com and in the root of the site I have a /holding/index.html file, how can I write my .htaccess to show the index of the holding page without showing the URL mysite.com/holding/ in the address bar.

Here is my directory structure:

public_html
└── .htaccess
└── holding
    └── index.html
    └── assets (css, img)
└── email-signature
    └── assets (img)

My .htaccess is currently:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/email-signature/assets/logo.jpg$
RewriteCond %{REQUEST_URI} !^/email-signature/assets/spacer.gif$
RewriteCond %{REQUEST_URI} !^/holding/(.)*$ [NC]
RewriteRule ^(.*)$ /holding/ [R=302,L]

But this shows mysite.com/holding/ in the address bar ... I want it to stay as mysite.com but still show the holding page index. Is this possible?

The email signature assets need to be accessible at mysite.com/email-signature/assets/... (I'd also like to not have to specify each file in the .htaccess but just wildcard all jpg,png,gif files in email-signature/* as accessible).

Thanks in advance.


Solution

  • You can refactor your rule to this:

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} !^/email-signature/ [NC]
    RewriteRule !^holding/ /holding/ [NC,L]
    
    • Remove R=3xx flag to avoid external redirect
    • Add this just below section of your page's HTML: <base href="/holding/" /> to resolve relative paths of css/js/images etc.