Libbna / BLOG_SITE

Simple blog site with CRUD operations using PHP and MYSQL
2 stars 4 forks source link

For security purpose clean the URL or remove the file extension from URL #17

Closed Libbna closed 3 years ago

Libbna commented 3 years ago

For this, you have to create a .htaccess file.
.htaccess -> provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory.

And in this file, rewrite some rules, for example, I wanted to remove the .php extension from URL so for that I wrote *RewriteRule ^(.)$ $1.php [NC,L].**

image In the attached image, the extension of the page is removed.

Libbna commented 3 years ago

Added the base tag in a header file which is common to all the pages. Base tag is added to specify the base URL for all relative URLs in a document.

For clean URL I have to remove the query string from the URL but after rewriting the rules and conditions in the .htaccess file it is giving me internal server error.

Libbna commented 3 years ago

Moved the page to the root folder and rewrite the rules for removing the query string from the URL. RewriteRule ^blog-single/([a-zA-Z0-9-/]+)$ blog-single.php?id=$1 [NC,L]

Blog-single is a page that I've moved to the root folder.