开发者

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/pa开发者_开发百科th)

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜