How to hide .php from the address bar

I use php to create web applications, but I need my web pages without the .php extension in the browser address bar. For eample, http://www.example.com/index.php displayed as http://www.example.com/index in the address bar of the browser.

How can i do this?

+7
source share
12 answers

Put this in a file called .htaccess in your WWW root:

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php 

This works if you use Apache and activate mod_rewrite.

+9
source

Just create a .htaccess file in wamp / www / and copy this code.

 Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.+)$ /$1.php [L,QSA] 

Hope! it would be helpful for someone !!

+4
source

You need to find the appropriate method for your web server. It allows you to display

www.domain.com/page

to

www.domain.com/page.php

+3
source
 Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / # To externally redirect /dir/foo.php to /dir/foo/ RewriteCond %{THE_REQUEST} ^[AZ]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L] # To internally redirect /dir/foo/ to /dir/foo.php RewriteCond %{DOCUMENT_ROOT}/$1.php -f RewriteRule ^(.*?)/?$ $1.php [L] 
+2
source

On systems using the Apache web server, you should use mod_rewrite.

In newer versions of IIS, you can use your version of mod_rewrite. In older versions you need to buy a plugin.

Stack Overflow Article

Search and you should find the answers to your questions.

+1
source

Just note that in older versions of IIS, such as IIS6, and assuming you are in a 32-bit process, IONICS ISAPI Rewrite is a fantastic free URL rewriting module. Inside the 64-bit in IIS 6, I found the commercial product Helicon ISAPI Rewrite 3 a great tool. But if you're in 32 bits, IONICS is free and does everything you need.

http://iirf.codeplex.com/

+1
source
+1
source

In apache2.conf I have

 <Files data> ForceType application/x-httpd-php </Files> 

This means that data treated as a PHP file without extension

+1
source

There are several ways to do this.

You can use mod-rewrite to overwrite foo in foo.php so that requests for / bar are handled by / bar.php.

You can use the default directories and files to refer to directcory / foo /, which is handled by /foo/index.php

You can set the php script as a handler for 404 errors, then you simply link to unused files, and the file handler deals with it, no matter how much it likes. (usually using some map from url to php file)

You can tell your web server that all requests for a specific web server should be handled by php.

The first or second solution is the simplest, but the last two offer the best flexibility, and their options are what most of the larger frameworks do.

+1
source

Here is a primer on how to rewrite a URL.

+1
source
 little modification - better to use REQUEST_URI and check for the directory # Turn mod_rewrite on RewriteEngine on # To externally redirect /dir/foo.html to /dir/foo/ RewriteCond %{REQUEST_URI} ^(.+)\.html?$ [NC] RewriteRule ^ %1 [R,L] # To internally redirect /dir/foo/ to /dir/foo.html RewriteCond %{DOCUMENT_ROOT}/$1 !-d RewriteCond %{DOCUMENT_ROOT}/$1.html -f RewriteRule ^(.*?)/?$ $1.html [L] # To externally redirect /dir/foo.html to /dir/foo/ RewriteCond %{REQUEST_URI} ^(.+)\.html?$ [NC] RewriteRule ^ %1 [R,L] # To internally redirect /dir/foo/ to /dir/foo.html RewriteCond %{DOCUMENT_ROOT}/$1 !-d RewriteCond %{DOCUMENT_ROOT}/$1.html -f RewriteRule ^(.*?)/?$ $1.html [L] 
+1
source

 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 
0
source

All Articles