As you suspect, you need to internally rewrite the request, not externally redirect (301/302). No "proxies" are required. You are almost there with what you have, except that when you specify an absolute URL in the RewriteRule
substitution Apache will implicitly trigger an external redirect (despite the docs suggesting that if the domain matches the current host it should be stripped - it doesn't do this in .htaccess in my experience).
Try something like the following:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^foo-bar$ index.html [L]
Unless you are serving mutliple domains then you probably don't need the RewriteCond
directive? (The NC
flag here is simply a security measure to catch malformed requests.)
I appended a $
(end of string) anchor on the RewriteRule
pattern to make it an exact match for "foo-bar" and not a URL that starts "foo-bar". The substitution should reference your DirectoryIndex document (index.html
, index.php
, or whatever document is loaded by default in the document root). I've removed the NC
flag, unless you specifically need a case-insensitive match?
UPDATE: There actually are some Wordpress ...
Ah, WordPress is the "problem" here. In fact, WP already rewrites all requests through index.php
in the document root, so these new directives (to "rewrite specific path to root domain but keep full path") are entirely redundant.
WP then uses the URL (the visible path in the address bar) ie. "/foo-bar" in this case, to route the request. Unless "/foo-bar" is defined as a valid URL in WP itself then WP is going to generate a 404 Not Found.
This is something you need to configure in WP itself, not .htaccess.