WHMCS .htaccess Remove .php and .html - php

Does anyone know how to specifically write an .htaccess file to remove .php from WHMCS client area, for example clientarea.php to clientarea. Also this will be needed to remove the .html extension from the knowledgebase articles as well.
I have tried this below but it is not working:
#Force non-.php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Thank you for any help in advance!

This should work:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
HTML is the same story, change .php to .html so it would look like this.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ $1.html
To have them both, the .htaccess should look like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ $1.html
Make sure to have mod_rewrite enabled ! If you do not have mod_rewrite enabled, this won't work.

Mod_Rewrite is compiled with Apache by default on cPanel.
Code:
root#server [~]# httpd -l|grep rewrite
mod_rewrite.c
You can enable it in cPanel for an account through the .htaccess file with a line such as:
RewriteEngine on
If you don't have cPanel I'm assuming the command would be some what the same but check if that doesn't work for you.

Related

Removing file extensions & redirecting to index page

So I am trying to get my site to remove all file extensions so instead of https://multimap.xyz/error/id.php?=... it will just be https://multimap.xyz/error/id?=... . Simarly I should be able to do https://multimap.xyz/mail/index.php and it removes the trailing index.php to result in just https://multimap.xyz/mail/.
I'm trying to achieve this with both .php and .html file extensions and indexes and using .htaccess and this is what I have so far
php_flag display_errors off
ErrorDocument 404 https://multimap.xyz/error/id?=404
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
This works well for removing file extensions. So the .../error/id?=... works perfectly. However when trying to access https://multimap.xyz/mail/ it shows me an error page saying
The requested URL /email/.php was not found on this server.
Any help/suggestions are appreciated.
Thank you :)
You should check presence of .html and .php file before their rewrites.
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index|(\S+?))\.(?:php|html)[/\s?] [NC]
RewriteRule ^ /%1%2 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

Remove extensions for both .html and .php in apache

The code is mixed to I have .html and .php in the same folder. There is never a time there there is the same name but different extensions. I have some code that should work but doesn't. The html part works but when I try to request a PHP page without an extension the URL it gives a 404
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -F
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -F
RewriteRule ^(.*)$ $1.php
You can try this on the .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]

Removing .php extension from URL not working

I have added .htaccess file to my directory. When I am writing http://lootainment.in/koovs its working. But when I am writing http://lootainment.in/koovs/ its not working. My htaccess file code is following :-
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Make trailing slash optional in your rule and remove directory check condition:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php
Try this,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.|/]+)$ $1.php [NC,L]
At first check your php.ini settings for Server API if your server api is 1)apache, 2)apache2filter, 3)apache2handler or like then only you can use .htaccess file. In htaccess file if your php version is php5 then use <IfModule mod_rewrite.c> block to write this code
try this code
RewriteEngine On
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php

hide .php extension from address bar also open a page without .php extension

I want open my page without .php extension like www.myweb.com/guest and also hide .php from address bar if user go to any page of my web. I tried many way to remove it to see these web link1 and link2 and many post on StackOverflow web but these are not working.
My domain from Godaddy And hosting from ONELANCER here Apache Version 2.2.27 PHP Version 5.4.28
Please give me a guideline.
I tried to add these into my .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
also
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
and also
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
and also
#RewriteEngine on#
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ %1%2 [R=302,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

Changing "index.php" Within The Address

I am developing a website in which i want to change my page home.php into page home
I tried this .htaccess code
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php page=/$1 [L,QSA]
Please help me.
Just this:
RewriteEngine On
RewriteRule ^(.*)$ $1.php [L,QSA]
Try this:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Replace html with your file extension, eg: php, htm, asp
This will work on local, but when you release your project don't forget to check if rewrite is enabled for the current server.

Categories