1

for instance if a page name is request.php

I should be able to request the page http://domain.com/request

I'm wondering how can it be done? .htaccess? or some other measure, please give an example in case.

Please advise.

anubhava
  • 761,203
  • 64
  • 569
  • 643
user2727195
  • 7,122
  • 17
  • 70
  • 118
  • Yep you can do that with .htaccess if you do some searching you should be able to find about a thousand examples. – Pitchinnate Sep 11 '13 at 15:03

3 Answers3

2

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    If you have php files named the same as directories but with .php on them then just remove the following line: `RewriteCond %{REQUEST_FILENAME} !-d` And change `Options +FollowSymLinks -MultiViews` to `Options +FollowSymLinks -MultiViews -Indexes` – Kevin Andrews Jan 14 '14 at 23:40
0
RewriteRule ^(.*)$ index.php?query=$1 [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
Debakant Mohanty
  • 805
  • 1
  • 10
  • 19
-1

You can enable this behavior globally in the server with MultiView and mod_negotiation:

http://httpd.apache.org/docs/2.2/mod/mod_negotiation.html

In centos (with plesk) you should edit:

/etc/apache2/sites-enabled/000-default 

in Debian and Ubuntu systems should be:

/etc/httpd/sites-enabled/000-default 
Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160
  • downvoted because a) you presumed apache b) you presumed centos and c) you presumed plesk. none of these technologies were introduced by the original question, and thus the response does not address the question at hand. beyond that the answer doesn't actually even work. sad day. – XaxD Sep 11 '13 at 15:14
  • .htaccess is *usually* Apache, I've written a solution for both CentOS and Debian based systems, the file is also the same for not-plesk systems but I'm not 100% sure so I've specified Plesk, seen my server has plesk. Now remove the downvote – Fez Vrasta Sep 11 '13 at 15:17
  • your was a copy of another reply, the other one is too specific, the OP is asking about a general way to apply the beahvior to every .php file, not just specified ones. – Fez Vrasta Sep 11 '13 at 15:22