I have a folder in which HTML pages are saved. I am including these pages with PHP include function. I am calling these pages in index.php with URL parameter value, where URL parameter xpage is equal to page name that are saved in my another folder & index.php is saved in root folder.
How I redirect to 404 page with htaccess if parameter xpage value named HTML page not found in that another folder?
http://example.com/about-me
Where about-me
is the name of page which is exists in my another folder as about-me.html. I want if this about-me.html doesn't exist in folder then redirect URL to URL http://example.com/404
I also want if url parameter is welcome,home and index then remove it and go to main domain http://www.example.com
It would be helpful if you included some code, but I will make a guess
you don't need to use .htaccess for this
<?php
$file = "somefolder/" . $_GET["urlparm"] . ".html";
if ( file_exists( $file) ) {
include_once( $file );
} else {
http_response_code(404);
include_once('somedefault404.php');
die();
}
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.