4

i need to hide full path and show shortly:

www.site.com/this/is/path/to/hide/page.php --> www.site.com

Any idea to do it with .htaccess apache and rewrite rules??

EXAMPLE:
If i type www.site.com i want open index.php (in /),
but if i go to /hidden/path i want to open file.php (in hidden/path)
mantaining browser url in www.site.com.


EDIT:
i want to see in the browser bar www.site.com and i want to open page at /this/is/path/to/hide/page.php .

thanks

elp
  • 8,021
  • 7
  • 61
  • 120

3 Answers3

3

As I explained in : How does url rewrite works? every rewrite triggers a new call to the rewritten URL. (HTTP 3xx code).

So the client will ask for www.site.com/this/is/path/to/hide/page.php, would be redirected to www.site.com and will be served the index page as a normal user.

There is no way to tell the client to display one URL in the browser bar instead of another, client browser will always make a new request. (Or you could impersonate any site for example)

If you are not against the use of a cookie, or can use environment variable you may be able to do something like :

RewriteRule this/is/path/to/hide/page.php / [co:knowHiddenPath=true] 

The environment variable as same syntax with E instead of co.

(See http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html for cookie information)

Your index page should then check this cookie/variable to serve the hidden page or not.

Another solution would be to enable access with password to your file. So even if someone know the URL he would not access the file. Security by obscurity is does not exists.

Community
  • 1
  • 1
M'vy
  • 5,696
  • 2
  • 30
  • 43
0

You can I believe do that with an Alias,

Alias / /this/is/path/to/hide/page.php

This directive needs to be in your <VirtualHost>

Mridul Kashatria
  • 4,157
  • 2
  • 18
  • 15
  • Now the only thing that you would show is the the file: `page.php`. **Yes path will be still be hidden.** – ssapkota Jun 26 '11 at 18:58
  • VirtualHost is not in htaccess, true? What kind of file that i need to do? Where? – elp Jun 26 '11 at 19:09
0

This will use mod_rewrite and you can put this into your .htaccess

# Activate Rewrite Engine
RewriteEngine On

# Home page rewrite rule
RewriteRule ^$ /this/is/path/to/hide/page.php [QSA,L]

This will ONLY work if you hit website root (e.g. http://www.example.com/)

LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • @LazyOne Ok, but i need to do exactly the opposite! I go to /hidden/path.php and i want see www.mysite.com. thanks. – elp Jun 26 '11 at 19:37
  • @Paska What do you mean by "see"? You want to be **redirected** to the root -- e.g. you type that path in the browser and it redirects you to the root and you see just `www.mysite.com` in the browser bar? Or you want that URL stays the same in address bar (as you typed) but it will show you (in the browser) the home page? – LazyOne Jun 26 '11 at 19:48
  • Sorry, i want to see in the browser bar www.site.com and i want to open page at /hidden/path.php. – elp Jun 26 '11 at 19:51
  • @Paska So you type `www.site.com` but want to see the `www.site.com/hidden/path.php` instead and browser should keep URL as is. Is that correct? – LazyOne Jun 26 '11 at 19:53
  • No, if i type **www.site.com** i want see **index.php (in /)**, but if i go to **/hidden/path** i want to see **file.php (in hidden/path)** **mantaining browser url in www.site.com**. – elp Jun 26 '11 at 19:57
  • 1
    @Paska That does not work just like that. It has to be something else involved. You cannot do what you want by just doing URL rewriting. No. Maybe you can show some real example (from real site) so I can look and understand better what you want to achieve and maybe explain you how they did it? – LazyOne Jun 26 '11 at 20:02