I want to run PHP files without .php extension.

For eg:-

If i open

myhost/docs/default

it should run "default.php".

Please tell me how to implement it.

Recommended Answers

All 9 Replies

what webserver are you using?

just configure it as a default document.

this might be a little bit different from what you want but you can place an index.php file inside myhost/docs/default and place a code index.php which will redirect you to any page that you wish in this case default.php

or just add default.php to the default document list along with index.php etc...

or use the include("default.php") inside index.php

this might be a little bit different from what you want but you can place an index.php file inside myhost/docs/default and place a code index.php which will redirect you to any page that you wish in this case default.php

or just add default.php to the default document list along with index.php etc...

or use the include("default.php") inside index.php

Those sound like pritty patchy solutions to me and why not do what wikipedia does of many people who own a copy of the mediawiki/wikipedia content management system. The way wikipedia does it is by using an apachie httpd.conf file modification to contain 2 rules simular to the following and more about that can be found about half way down the page at
http://www.mediawiki.org/wiki/Manual:Short_URL
The link has according to the preview being replaced with a smily so I have also placed the above link in the codebox below:

http://www.mediawiki.org/wiki/Manual:Short_URL

And those rules as they are called are:

Alias /wiki /path/to/your/wiki/index.php
Alias /wiki /var/www/w/index.php

If you wish to edit apachie for faster performance then you may do so with more information at the above link the the prefered method that most people do is using a .htaccess file as it does not require root access. So place at myhost/docs/ a file named '.htaccess' without the quotes and place the following code in it.

RewriteEngine On
RewriteRule ^default$ default.php

There is also a syntax you can use if you are doing this to multiple files. So generally I would use the .htaccess method

what webserver are you using?

just configure it as a default document.

I am using XAMPP for developing my website.

I have set "index.php" as default document but that does not solve my problem

I want to run php files without .php extension.

For eg:-

"myhost/docs/index"

should run "index.php"

If you are using Xampp then you will need to enable the rewrite module in the apache httpd.conf file to use the .htaccess files(located C:/xampp/apache/conf/httpd.conf). To do this, first create a copy of the file located C:/xampp/apache/conf/httpd.conf or relative to your installation folder then open the original in notepad. After opening it in notepad, search for the term "LoadModule rewrite_module" without the quotes and when you find it, remove the hash at the beginning of the line. Then search for "AllowOverride None" without the quotes and at least twice will be found and need replacing with "AllowOverride All" (without the quotes). Then save the file and you should be able to use .htacess files. Another set of instructions just reworded of what I have said can be found at http://www.knowledgebase-script.com/demo/article-599.html
You may wonder how I know this, because I also have Xampp. Also when renaming a text file to ".htaccess", you may find that to be impossible to do due to a windows explorer error bug so just open notepad and save the file as ".htaccess" and that will create the file.

Also if it is all files you want to not have the extension use the following code in the .htaccess file.

RewriteEngine On
RewriteRule ^([^.]+)$ $1.php

Give this a whirl -

RewriteEngine On

RewriteBase /

RewriteRule ^()$ index.php [NC,L]

Rewritecond %{REQUEST_URI} !(^/?.*\..*$) [NC]

RewriteRule (.*)$ $1.php [NC]

But where to write it for linux system

commented: Avoid new questions in 12 year old discussions. Few may notice your question. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.