Drew Peer
Drew Peer

Reputation: 377

How do I hide a /public/ directory in htacess

My website is website.com/public/login.php. That looks a bit ugly. How do you rewrite htaccess to say website.com/login.php?

I've tried

RewriteEngine On
RewriteBase /public/

RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]

RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

Upvotes: 0

Views: 36

Answers (2)

Drew Peer
Drew Peer

Reputation: 377

   Solved. It hides /public/ 
   website.com/login.php instead of 
   website.com/public/login.php

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>

Upvotes: 0

Roland Illig
Roland Illig

Reputation: 41625

The RewriteRule that strips off the /public/ path is currently an external redirect, because of the R=. Since you want the result of that rule to be hidden, it should rather be an internal redirect (also called URL forwarding), and that is written without the R=302 option.

While you're at it, you could also hide the .php from the externally visible URLs since a simple /login looks much cleaner than /login.php.

Upvotes: 1

Related Questions