简体   繁体   中英

Rewrite rules to hide an url

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

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.

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>

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 (eg http://www.example.com/ )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM