skip to Main Content

I’m trying to remove the file extension from the url of the static pages
sitename.com/page.phpsitename.com/page

I made it so that my wp url looks like this (if it matters)
sitename.com/wp/sitename.com/

FTP looks like this:

- root directory
  - static php files
  - htaccess file
  - wp folder

Adding this to .htaccess doesn’t do anything

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

Current .htaccess contents:

ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
ErrorDocument 403 /403.php

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

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

How do I achieve this by only adding a code in the .htaccess file?
Thank you in advance!

2

Answers


  1. Chosen as BEST ANSWER

    I realized the files are getting overwritten so the only way I can go about it is to create individual folders for each static file (i.e., page/index.php) so that I can achieve this sitename.com/page.phpsitename.com/page


  2. The steps to remove file extensions are:

    1. Login to your cPanel account.
    2. Go to File Manager – in the FILES Section
    3. In the File Manager go to the Settings button on the top right corner.
    4. On the Preferences window that will appear, check the Show Hidden Files (dotfiles) option. Click the Save button to apply the settings.
    5. Now navigate to the .htaccess file. If the file doesn’t exist you will need to create it.
    6. Click the Edit button from the File Manager top menu.
    7. Add the below lines to the .htaccess file. Click the Save Changes button and then the Close button.

    #remove php file extension-e.g. https://example.com/file.php will become https://example.com/file

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME}.php -f
        RewriteRule ^(.*)$ $1.php [NC,L] 
    
    1. Now the Apache web server will remove .php extension from URLs.

    To remove .html extension use:

    #remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*)$ $1.html [NC,L]
    

    You can also edit .htaccess files on your web hosting account via an
    FTP client like FileZilla.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search