[英]How to redirect page with htacces with URL parameter
我有一个文件夹,其中保存了 HTML 页面。 我将这些页面包含在 PHP 中,包括 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.
如果在另一个文件夹中找不到名为 HTML 页面的参数 xpage 值,我如何使用 htaccess 重定向到 404 页面?
http://example.com/about-me
其中about-me
是我的另一个文件夹中存在的页面名称 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
如果您包含一些代码会有所帮助,但我会猜测
你不需要为此使用 .htaccess
<?php
$file = "somefolder/" . $_GET["urlparm"] . ".html";
if ( file_exists( $file) ) {
include_once( $file );
} else {
http_response_code(404);
include_once('somedefault404.php');
die();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.