How to remove .php, .html, .htm extensions with .htaccess

How to remove .php, .html, .htm extensions with .htaccess

What is an .htaccess file
An .htaccess file may be a simple ASCII file that you simply create with a text editor like Notepad or TextEdit. The file lets the server know what configuration changes to form on a per-directory basis.

Please note that .htaccess is that the full name of the file. It isn’t file.htaccess, it’s simply .htaccess.

.htaccess files affect the directory during which they’re placed in and every one children (sub-directories). for instance if there’s one .htaccess file located in your root directory of yoursite.com, it might affect yoursite.com/content/, yoursite.com/content/images/, then on…

It is important to recollect that this will be bypassed. If you don’t want certain .htaccess commands to affect a selected directory, place a replacement .htaccess file within the directory you don’t want to be affected with the changes, and take away the precise command(s) from the new file.

Features
With an .htaccess file you can:

Redirect the user to different page
Password protect a selected directory
Block users by IP
Preventing hot-linking of your images
Rewrite URLs
Specify your own Error Documents
In this tutorial we’ll be focusing only on rewriting URLs.

Removing Extensions
To remove the .php extension from a PHP file for instance yoursite.com/wallpaper.php to yoursite.com/wallpaper you’ve got to feature the subsequent code inside the .htaccess file:

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

If you would like to get rid of the .html extension from an HTML file for instance yoursite.com/wallpaper.html to yoursite.com/wallpaper you merely need to change the last line from the code above, to match the filename:

RewriteRule ^([^\.]+)$ $1.html [NC,L]

That’s it! you’ll now link pages inside the HTML document without having to feature the extension of the page. For example:

wallpaper
Adding a trailing slash at the top
I received many requests asking the way to add a trailing slash at the top, for example, yoursite.com/page/

Ignore the primary snippet and insert the code below. the primary four lines affect the removal of the extension and therefore the following, with the addition of the trailing slash and redirecting.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

Link to the HTML or PHP file an equivalent way as shown above. Don’t forget to vary the code if you would like it applied to an HTML file rather than PHP.

For Example

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^location/([0-9a-zA-Z_]+) job-by-city.php?city=$1
RewriteRule ^category/([0-9a-zA-Z_]+) job-by-category.php?category=$1

RewriteRule ^openings/([0-9a-zA-Z_]+)/([0-9a-zA-Z_]+) jobs-link.php?city=$1&category=$2

RewriteRule ^details/([0-9]+) job-details.php?jdid=$1

ErrorDocument 404 /404.php

RewriteRule ^jobs-in-delhi?$ jobs-in-delhi.php

Some people asked how you’ll remove the extension from both HTML and PHP files. I don’t have an answer for that. But, you’ll just change the extension of your HTML file from .html or .htm to .php and add the code for removing the .php extension.

How to Increase the Maximum File Upload Size in WordPress

How to Check Your Maximum File Upload Size Limit in WordPress?

WordPress will automatically show the utmost file upload size limit once you are uploading images or media. to see it you’ll simply attend Media » Add New page and you’ll see the utmost file uplaod size limit for your WordPress site.

1: Theme Functions File

There are cases where we have seen that just by adding the following code in theme’s functions.php file, you can increase the upload size:

@ini_set( 'upload_max_size' , '32M' );
@ini_set( 'post_max_size', '32M');
@ini_set( 'max_execution_time', '300' );

htaccess Method

Some people have tried using the .htaccess method where by modifying the .htaccess file in the root directory, you can increase the maximum upload size in WordPress. Edit the .htaccess file in your WordPress site’s root folder and add the following code:

1
2
3
4
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
how to remove .php extension from url in php

how to remove .php extension from url in php

remove .php extension from url in php

Just follow these steps

Open .htacess file and copy below code in .htacess file

 
RewriteEngine On

RewriteRule ^test?$ test.php

Here test is your page name
Now you can visit your page like abc.com/test

remove ?id from url in php

if your url is user.php?id=1
then just copy the below code in your htacess file
RewriteEngine On

RewriteRule ^user/([0-9]+) user.php?id=$1



RewriteRule ^test?$ test.php

RewriteRule ^user/([0-9]+) user.php?id=$1


RewriteRule ^shop/cat/([0-9a-zA-Z]+)/subcat/([0-9a-zA-Z]+) shop.php?cat=$1&subcat=$2




  That’s It. Now you see a magic in your url [avatar user=”basant” size=”60″ align=”left” /]    
dynamic menu submenu in php

dynamic menu submenu in php

Dynamic menu submenu in php

you can create dynamic menu submenu using php and mysqli.

just follow below code

[avatar user=”basant” size=”medium” align=”left” link=”basantmallick.com” /]

active class using php In 5 Minutes

active class using php In 5 Minutes

You can simply follow steps and add active class in your navigation using PHP

Step1:  In Header page Modified navigation link as per your need

<li class=”nav-item <?php if ($phpSelf==”index.php”) { echo “active”; } ?>”><a href=”index.php” class=”nav-link”>Home</a></li>
<li class=”nav-item <?php if ($phpSelf==”about.php”) { echo “active”; } ?>”><a href=”about.php” class=”nav-link”>About</a></li>
<li class=”nav-item <?php if ($phpSelf==”menu.php”) { echo “active”; } ?>”><a href=”menu.php” class=”nav-link”>Menu</a></li>
<li class=”nav-item <?php if ($phpSelf==”blog.php”) { echo “active”; } ?>”><a href=”blog.php” class=”nav-link”>Stories</a></li>
<li class=”nav-item <?php if ($phpSelf==”contact.php”) { echo “active”; } ?>”><a href=”contact.php” class=”nav-link”>Contact</a></li>
<li class=”nav-item cta”><a href=”reservation.php” class=”nav-link”>Book a table</a></li>

Step2: Open particular page like index.php,about.php so on..

Step3: Add these code before including header.php

$phpSelf = trim(basename($_SERVER[‘PHP_SELF’]));

That’s It. Now you can see your navigation link has active class

Thanks. Basant Mallick