Jump to content
[MUST READ] Forum Rules ×

Remove file extensions


Moussa

Recommended Posts

How to remove file extensions

Hello all i made this post to show you how to remove file extensions likewww.example.com/index.php ] now i will show you how to remove .php in the end file to be [ www.example.com/index ] it will help your clients to open your website now follow this steps :

  1. open new Notepad
  2. save this code in new notepade
RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ https://yourwebsitelink.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ https://yourwebsitelink.com/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
  1. Now change https://yourwebsitelink.com with your website link there is two to changeing
  2. Save the Notepade with name .htaccess and uploade with your website files and see what will happend

Link to comment
Share on other sites

  • 1 year later...
On 21/3/2017 at 9:21 PM, Moussa said:

How to remove file extensions

Hello all i made this post to show you how to remove file extensions likewww.example.com/index.php ] now i will show you how to remove .php in the end file to be [ www.example.com/index ] it will help your clients to open your website now follow this steps :

  1. open new Notepad
  2. save this code in new notepade

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ https://yourwebsitelink.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ https://yourwebsitelink.com/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
  1. Now change https://yourwebsitelink.com with your website link there is two to changeing
  2. Save the Notepade with name .htaccess and uploade with your website files and see what will happend

 

Thanks for this code! I assume it works with HTML also, I will definitely give it a try!

Link to comment
Share on other sites

5 hours ago, PCTipsGR said:

Thanks for this code! I assume it works with HTML also, I will definitely give it a try!

That code is specifically for removing PHP. To remove the .html extension, just rewrite the code a little bit

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

 

Link to comment
Share on other sites

13 hours ago, xpde said:

That code is specifically for removing PHP. To remove the .html extension, just rewrite the code a little bit


RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

 

Thanks for posting that here!

I know your time is valuable and so I thank you for giving time to see this post and answer.

Link to comment
Share on other sites

On 10/5/2018 at 9:41 AM, PCTipsGR said:

Thanks for posting that here!

I know your time is valuable and so I thank you for giving time to see this post and answer.

Nah, you're good man. I'm just trying to help another person out.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...