Ocaccy Pontes
Ocaccy Pontes

Reputation: 257

Hide the directory in the address bar of the browser

The file .htaccess has this directive:

RedirectMatch permanent ^$ /moby/

When I type the website address into the address bar in the browser: http://mobyx.net/ it appears the directory redirected to: http://mobyx.net/moby/

How to hide the directory?

Upvotes: 0

Views: 2084

Answers (1)

Sumurai8
Sumurai8

Reputation: 20737

You are currently doing a redirect (you tell the client to try again on mobyx.net/moby if they go to mobyx.net). What you actually want to do is an internal rewrite. This is invisible to the client. You can use RewriteRule for that. See the documentation for more information.

First make sure that mod_rewrite is enabled in httpd.conf. Then add the following to your .htaccess

RewriteRule ^$ /moby/ [L]

This will internally rewrite http://mobyx.net/ to http://mobyx.net/moby/, but not http://mobyx.net/index.php for example. If you want everything to be rewritten on your site, use:

RewriteCond %{REQUEST_URI} !^/moby
RewriteRule ^(.*)$ /moby/$1 [L]

This will rewrite the url if it doesn't already point to the /moby subdirectory.

Upvotes: 1

Related Questions