简体   繁体   English

如何向网站访问者隐藏页面URL?

[英]how to hide page URLs from the website visitor?

Whenever a user clicks a link like www.mywebsite.com/hello.php , I want www.mywebsite.com to appear in his address bar. 每当用户单击诸如www.mywebsite.com/hello.php类的链接时,我希望www.mywebsite.com出现在他的地址栏中。 I tried modifying the .htaccess file for this. 我尝试为此修改.htaccess文件。 The rules worked for the home page. 规则适用于主页。 But whenever I click a link, the php page for that link appears in the address bar. 但是,每当我单击一个链接时,该链接的php页面就会出现在地址栏中。 How can I hide the names of page even after a link is clicked. 即使单击链接,如何隐藏页面名称。

RewriteEngine On
RewriteRule ^site$ /*.php [L]

Eg. 例如。 When I type mywebsite.com/index.php it shows only mywebsite.com . 当我输入mywebsite.com/index.php它仅显示mywebsite.com But if I click a link in the page, like <a href="mypage.php">My Page</a> , mywebsite.com/mypage.php appears in the URL. 但是,如果我单击页面中的链接,例如<a href="mypage.php">My Page</a> ,则mywebsite.com/mypage.php出现在URL中。

In .htaccess , add a redirection rule for each of your paths. .htaccess中 ,为每个路径添加一个重定向规则。 Each rule will tell the server which webpage to serve when the browser requests a human friendly paths. 当浏览器请求人性化的路径时,每个规则都会告诉服务器要提供哪个网页。 For instance: 例如:

Rewrite On
RewriteRule ^home/?$          /home.php      [END,NC]
RewriteRule ^about/?$         /about.php     [END,NC]
RewriteRule ^products/?$      /pages/products.php      [END,NC]
...

Then in your pages, use the pretty links for hrefs: 然后在页面中,使用漂亮的href链接:

<a href="/products">Products</a>

I think there are two problems here: 我认为这里有两个问题:

  1. Your link <a href="mypage.php">My Page</a> should be <a href="mypage">My Page</a> 您的链接<a href="mypage.php">My Page</a>应为<a href="mypage">My Page</a>

  2. From what I understand you don't only want one specific URL to be forwarded, so you should write a more general rule like RewriteRule ^(.*)$ $1.php . 据我了解,您不仅希望转发一个特定的URL,因此您应该编写更通用的规则,例如RewriteRule ^(.*)$ $1.php This lets you access any URL without the .php extension. 这使您可以访问任何不带.php扩展名的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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