Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mod Rewrite Hide Folder

I think this is a pretty simple question.

How do you an apache rewrite to hide a folder.

EX: www.website.com/pages/login.php to www.website.com/login.php

or www.website.com/pages/home.php to www.website.com/home.php

The folder needs to alway be hidden. thanks

like image 420
blah Avatar asked Apr 11 '10 19:04

blah


2 Answers

I know the original post here was from a couple years ago, but it's been coming up first in the search engine, so maybe this will help others looking to hide a folder name in the URL.

Not exactly what original poster wanted, but along the same lines.

RewriteCond %{HTTP_HOST} ^mydomainname\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomainname\.com$
RewriteCond %{REQUEST_URI} !^/subfoldername/
RewriteRule (.*) /subfoldername/$1

The above example would redirect any request to mydomainname.com or www.mydomainname.com to the subfoldername directory in the root directory for the domain, and the subfolder name would not appear in the URL.

like image 90
Gilbert Williams Avatar answered Nov 15 '22 18:11

Gilbert Williams


I assume what you want is for the browser to request /home.php but the server to actually use the file located at /pages/home.php, right? If so, this should work:

Make sure the apache mod_rewrite module is installed. Then, use something like this in your apache config, virtual host config, or (less desirable) .htaccess file:

RewriteEngine On
RewriteRule ^/(.*)$   /pages/$1

The rules use regular expressions, so you may want to look at a reference on that topic if you're unsure. Read the manual for more info on other directives (RewriteCond can be very useful) or rule options.

like image 25
grossvogel Avatar answered Nov 15 '22 20:11

grossvogel