How to add .php extension for particular file? - php

In my wordpress website i used a htaccess code to remove php extension. Then I again used a code to add php extension.
After that all files are accessible but when I click on plugins and contactform7 from my dashboard it opens https://ecxsolution.roundabouttech.com/wp-admin/plugins without extension and string after it and shows file not found.
I am not able to see all my forms even. Can somebody tell me how should I change .htaccess file to add extension for this particular file?
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

Related

how to remove .php file extension on static files htaccess

I'm trying to remove the file extension from the url of the static pages
sitename.com/page.php → sitename.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!
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.php → sitename.com/page
The steps to remove file extensions are:
Login to your cPanel account.
Go to File Manager – in the FILES Section
In the File Manager go to the Settings button on the top right corner.
On the Preferences window that will appear, check the Show Hidden Files (dotfiles) option. Click the Save button to apply the settings.
Now navigate to the .htaccess file. If the file doesn’t exist you will need to create it.
Click the Edit button from the File Manager top menu.
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]
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.

htaccess - add custom rewrite to standard wordpress rewrites

i have a wordpress website
i have uploaded some of my php code at the root of my web where wordpress is installed.
i want to open those page directly.
they open if # www.example.com/newcode.php
but i want to open them like www.example.com/newcode (without extension .php)
the problem is when i put some .htacess code to achieve this, all wordpress pages stops and shows error404 not found and if i remove htaccess code then i cant open my own newcode.php page without extension
i tried to put this code in htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^\.]+)$ $1.php [NC,L]
but doesnt work...
this is my wordpress .htaccess (automatically created by wordpress)
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^\.]+)$ $1.php [NC,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
id have more files like newcode.php and some folder in which there are more code files and i want all of them to open like this
i want both wordpress pages as well as my new code page to open without any extension and i cant put newcode.php in seperate folder and make another htaccess for that specific folder
This is documented pretty clearly - especially in this case where you don't even need any regexp knowledge. Simply replace everything before # BEGIN WordPress with:
RewriteEngine On
RewriteRule /newcode /newcode.php [L]

Why do I need to add index.php in order to route my website correctly? [getkirby]

I uploaded the code to the server. It started the homepage correctly . But when I press any link , I get 404 not found error. I discovered that I need to add index.php to my url for it to work.
so it will be like that:
mydomain.somee.com/myWebsite/index.php/anotherPage
When I was working locally using Xamp as a server, I didn't get any of those problems.
I got those problems after I uploaded the website to some.com which apparently doesn't use .htaccess file (editing or removing has no effect).
How to add this index.php automatically and hide it from the user?
I didn't change any of the system files or the htaccess
please tell me if you need anymore files or description.
You need to redirect all your all pages through index.php file but remove it from URL.
Write below rules in your root .htaccess file:-
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
OR
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
To understand, How htaccess rules are working, This link will help you :)
Hope it will help you :)

Remove .php extension within url

I've got a url http://example.com/pages.php/page-name and I want to remove the .php extension on the pages.php part... Is that possible with an .htaccess file or should I just give up?
I've tried RewriteRule ^(.+)\.php/(.+)$ $1/$2 from "Remove php extension from url" with no luck.
I'm new to .htaccess files (this is the first site my normal tricks don't work)
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+([^/.]+)\.php/(\S+)\s [NC]
RewriteRule ^ %1/%2? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)/([^/]+)/?$ $1.php/$2 [L,NC]

How to handle this URL?

I have http://www.example.com/contact-us.php URL which is working perfectly but if someone put http://www.example.com/contact-us.php/contact-us.php it shows the page with CSS disturbed.
Can we show page not found message to users for this http://www.example.com/contact-us.php/contact-us.php URL? If this page is or is not present.
Update :
My .htacess file - /public_html/.htaccess :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301]
You can create an htaccess file on your server and force trailing slash for all URLs that don't point directly to a file like this (do check whether mod_rewirte is enabled or not):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
#Force Trailing slash
RewriteRule ^((.*)[^/])$ $1/ [L,R=301]
</IfModule>

Categories