I have a 404 error page and tried the below code which was generated from this link . But when the wrong URL is entered it redirects to the main page, not to the 404 error page
<IfModule mod_rewrite.c>
RewriteEngine On
ErrorDocument 404 https://www.rcis.in/404.php
</IfModule>
I have added the code in htaccess file. And also how to remove the file extension from the URL. Down below is the code I tried
#Remove extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
And I tried below code which was generated from that website which is mentioned above
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/?(.*).(php)$ /$1 [R=301,L]
</IfModule>
How can I solve these two
Thank You in advance
The below code will remove php extention from the URL
RewriteEngine On
# for 404 redirection
ErrorDocument 404 https://www.yourdomain.in/404
# below code rewrites php extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
# Remove php extention
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
Hence the url https://www.yourdomain.in/404 will load https://www.yourdomain.in/404.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.