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?

- 802
- 1
- 7
- 21
-
1What "PHP extensions" are you talking about? How would they show up in your HTML source? Do you mean "extension" as in `/index.php`? – tadman Nov 08 '17 at 16:58
-
Please provide a specific example code snippet. – derHugo Nov 08 '17 at 16:58
-
@tadman I mean when you redirect your page with tag, you need to type the file name. For example, from index.php to about.php, you write . So how can I hide it? ( Hide the extension) – WebDeg Brian Nov 08 '17 at 17:00
-
Are you using apache? – Kisaragi Nov 08 '17 at 17:00
-
@WebDegBrian — You just don't type it in the HTML in the first place! – Quentin Nov 08 '17 at 17:01
-
2If you don't need to put them in to render the page properly (e.g. URL bar) then you don't need to put them in the source itself either. – tadman Nov 08 '17 at 17:01
-
you can just remove the `.php` part in the links in your anchor tags, as long as your .htaccess file is configured to handle that, which it sseems like it is since you mention you already know you can remove it from the url. – coderodour Nov 08 '17 at 17:01
-
It's part of the same process as hiding them in the URL bar. If you've implemented a "clean" URL that works in the address bar, then just use that in your links instead of the filename. – iainn Nov 08 '17 at 17:02
-
@Quentin I’m afraid that it won’t work when you type like that – WebDeg Brian Nov 08 '17 at 17:02
-
@WebDegBrian — Then you haven't set up the server correctly. If you set up the server so that you don't need `.php` in the URL then you never need `.php` in the URL. – Quentin Nov 08 '17 at 17:02
-
Need examples. Update your question. This is just too broad and everyone is just throwing guesses due to the lack of information provided. – IncredibleHat Nov 08 '17 at 17:03
-
@Quentin Let’s me have a look – WebDeg Brian Nov 08 '17 at 17:03
-
@Kisaragi Sure, I am using Apache – WebDeg Brian Nov 08 '17 at 17:08
-
@coderodour Thanks a lot, I will have a try – WebDeg Brian Nov 08 '17 at 17:09
-
If you have your server set up to not require the .php extensions on urls, you can also remove them from the anchor tags in your document body. That's no problem as long as apache/nginx/whatever is configured to interpret the extension-less urls correctly when entered in the URL bar. – Ambulare Nov 08 '17 at 17:09
3 Answers
If you already have configured your web server to interpret any chosen extension like ".do" as a php script instead of extension ".php", then all your links must use this chosen extension.
So it is not that you "can", it is you "must" use ".do" in your HTML pages.

- 2,262
- 13
- 28
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 example config:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [NC,L]
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>

- 70
- 8
The PHP code is not visible on Server side, when you click "View Page Source", however if you submit your URL for optimisation/analystics/SEM companies (bing or google or any other such company), they can get the complete PHP server code. So, it's not foolproof. Even the webpage that you installed on webhost, the PHP code can easily be viewed by the webhost employees itself. So, it's not safe (if your PHP code is critical for you).
To hide your code, you can write your main functionality in Java and port your compiled Java code to the webserver. This way, nobody can decode your code and yet you are able to achieve what you want to do.

- 1
- 3