-1

I want to remove my any extension of file from URLs of my website.

For example: www.example.ml/dash/logins/sign.php
to: www.example/dash/logins/sign/

I had done a lot of googling, but none of the answers worked for me. I think it didn't work, because in the logins folder I have not a single file.

There are many other files, like index.php, sign.php, etc. Do I have to keep each file in a separate folder or sing.php can change to sign/. Also, what would happen to this:

sign.php?usercode=1

Will it get converted to

sign/usercode=1

?

I already have some code present in .htaccess, so please give your answer after referring this code.

php_value display_errors Off
php_flag magic_quotes 1
php_flag magic_quotes_gpc 1
php_value mbstring.http_input auto
php_value date.timezone America/New_York

Options -Indexes

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.example.ml$ [NC]

RewriteRule ^(.*)$ https://www.example.ml/$1 [L,R=301]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

2 Answers2

0

Add this line to your .htaccess file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^\.]+)$ $1.php [NC,L]
J Shubham
  • 609
  • 7
  • 21
  • thanks it worked but after typing extension it is also opening, i want to force every url to remove its extension – Sidhant Sood Jul 09 '17 at 11:40
  • .htaccess can't restrict that. It js just rewriting your url. To do that, you have to create an intermediate page where uri will act as get parameter and pages will be shown based on that. Doing that will take more cost. – J Shubham Jul 09 '17 at 11:49
0

Use this code in your .htaccess file. It will redirect to PHP file into a non-PHP version.

# Turn on the rewrite engine
RewriteEngine  on
# If the request doesn't end in .php (case insensitive) continue processing rules
RewriteCond %{REQUEST_URI} !\.php$ [NC]
# If the request doesn't end in a slash continue processing the rules
RewriteCond %{REQUEST_URI} [^/]$
# Rewrite the request with a .php extension. L means this is the 'Last' rule
RewriteRule ^(.*)$ $1.php [L]

The example is taken from Tim Bielwa, Remove .php extension with .htaccess

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Saad Suri
  • 1,352
  • 1
  • 14
  • 26