我可以在HTML源代码中隐藏PHP扩展名吗 [英] Can I hide PHP extension in HTML source code

查看:69
本文介绍了我可以在HTML源代码中隐藏PHP扩展名吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以在URL栏上隐藏PHP扩展.当用户查看源代码时,我们可以隐藏PHP扩展吗? 例如,在index.php页面中(在网址栏上是abc.com/index) 我查看了源代码,.php扩展名仍然存在(在<a>标记中).我可以藏起来吗?

I know that we can hide PHP extensions on URL bar. Can we hide PHP extensions when the user view source code? For example, in the index.php page (on url bar it is abc.com/index) And I view the source code, the .php extension is still there (in <a> tags). Can I hide it?

推荐答案

如果您将服务器(Apache/Nginx)配置为与example.com/和(例如about.php)example.com/about一起使用,则链接会起作用.

If you configured your server (Apache/Nginx) to work with example.com/ and (lets say an about.php) example.com/about, the links would work.

Apache htaccess示例配置:

Apache htaccess example config:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [NC,L]

这只是针对php扩展.尽管这仅对链接有所帮助,但可以说您需要一个文件,但仍然需要扩展名,尽管该扩展名不会显示在浏览器的元素检查器/源代码中.

Thought this is just for php extensions. Though this will only help with links, lets say you are requiring a file you'll still need extensions though that wouldn't show up in element inspector/source code from browser.

<a href="./">Home</a>
<a href="./about">About</a>

这篇关于我可以在HTML源代码中隐藏PHP扩展名吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆