How to hide the file URL? (do not show the whole file up)

Asked

Viewed 5,460 times

1

Personal I want to hide the URL of the files, example: example.com/cadastro.php
would have some way to leave only example.com? Or some other way, but not show the complete path.
Thank you.

  • In the browser URL or in the html links?

  • it seems to me that he wants to say in the browser url @Sergio

  • In the browser URL.

3 answers

2

On the client side, with Javascript this is not possible to 100%.

You have two ways that go halfway, and that can serve you well:

  • iframes
  • rewrite the url via pushstate

iframe

<iframe src="url_a_esconder.php" />

so create a page inside the page to hide the content.

pushstate

window.history.pushState("", "", '/');

so re-write the url for the domain

2

Edit the .htaccess and put the code down

AddHandler application/x-httpd-php5 .htm
AddHandler application/x-httpd-php5 .html
AddHandler application/x-httpd-php5 .shtml
AddHandler application/x-httpd-php5 .php

to hide . html

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

to hide . php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
  • I put these commands on. htaccess but every time the page was loaded the option to download the file appeared, and the url was still complete.

  • See if you have put your php version correctly in the Addhandler application/x-httpd-php5 line. php Addhandler example if your server uses version 5 the code is correct if it still uses version 4 you must edit for Addhandler application/x-httpd-php4 . php Addhandler

0

If it is in the Browser URL, one of the options you can leave configured on your site is the User Friendly URL, and it is used. htaccess (for apache) and web.config (for IIS)

Example of . htaccess

Simple page example (No $_GET) - In your case

RewriteRule ^$ ./cadastro.php

From:/register.php
To: / = (site url)

Example with page with 1 $_GET

RewriteRule ^u/(..*)$ ./u.php?rl=$1 

From: /u.php? rl=Cposma3gev
To: /u/Cposma3gev

Example with page + 1 $_GET

RewriteRule ^pagina-(..*)-(..*)$ ./pagina.php?id=$1&outro=$2

From:/page? id=1&other=2
To: /page-1-2

There is no difference in formatting the new url, so I used / and - to show how it works.

If you want an example of . full htacces, I’ll leave one of mine here: http://pastebin.com/7J4dRVLK

  • put this on . htacces, but it didn’t work: Rewriteengine on Rewriterule $ . /valePontos.php

  • If it’s not too much to ask, I wonder if you could help me?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.