URL 重写不断重定向回 xampp 主页

问题描述 投票:0回答:1

我正在构建一个新版本的 PHP 网站以具有 SEO 链接 URL

我对 REGEX 真的很不好,并且对如何使用

.htaccess
知之甚少,但我已经尝试了两天来制定 URL 重写规则,我认为这几乎已经完成,但还没有完全实现。

在我的

.htaccess
我有:

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ .php?id=$1 [QSA,L]

这不仅仅是重写 URL 的末尾,而是重定向到 xampp 主页。请我真的很困惑,因为我已经尝试了几种。不知道是否是我的托管服务器的问题。

https://localhost/new%20owolab/?id=home

这是我的索引页:

main index page

/** Absolute path . */
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

// Version
define('VERSION', '1.0.6');
// Check Version
if (version_compare(phpversion(), '5.3.0', '<') == true) {
    exit('Please Upgrade To The Latest Version Of  PHP  From Version 5.3 + Required To Access This Site');
}

if (!ini_get('date.timezone')) {
    date_default_timezone_set('UTC');
}
// Windows IIS Compatibility
if (!isset($_SERVER['DOCUMENT_ROOT'])) {
    if (isset($_SERVER['SCRIPT_FILENAME'])) {
        $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF'])));
    }
}

if (!isset($_SERVER['DOCUMENT_ROOT'])) {
    if (isset($_SERVER['PATH_TRANSLATED'])) {
        $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF'])));
    }
}

if (!isset($_SERVER['REQUEST_URI'])) {
    $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);

    if (isset($_SERVER['QUERY_STRING'])) {
        $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    }
}

if (!isset($_SERVER['HTTP_HOST'])) {
    $_SERVER['HTTP_HOST'] = getenv('HTTP_HOST');
}

// Check if SSL
if (isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) {
    $_SERVER['HTTPS'] = true;
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
    $_SERVER['HTTPS'] = true;
} else {
    $_SERVER['HTTPS'] = false;
}



require_once "header.php";

if(isset($_GET['id'])){
    $id = $_GET['id'];
    $filename = "layout/" . $id . '.php';
    if(file_exists($filename)){
        include $filename;
    }else{
        include "system/error.php";
    }
}else{
    include "layout/home.php";
}

require_once "footer.php";
?>````
php .htaccess
1个回答
0
投票

我认为这会给你带来你需要的结果:

  1. 新网址 https://localhost/new-owolab/?id=home

https://localhost/newowolab/?id=home

  1. 旧网址 https://localhost/new%20owolab/?id=home
© www.soinside.com 2019 - 2024. All rights reserved.