首页 > 解决方案 > Apache 重写时出现白屏

问题描述

我正在尝试使用 .htaccess 并尝试将我的 .php 重写为另一个 url,但我一直在打白屏。

我可以确认我的 apache 重写正在访问正确的文件/文件路径,并且一旦重定向我的 php 和 html 就会被读取,但是一旦 url 被重写,我的函数由于某种原因无法正常工作。或者,我使用 WordPress 永久链接将 page-shop.php 更改为https://mhspeakers.com/shop/

我的htaccess如下:

RewriteOptions inherit
Options -Multiviews +FollowSymLinks

<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType text/html "access plus 5 minutes"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 6 hours"
</IfModule>
<ifModule mod_headers.c>
Header set X-Endurance-Cache-Level "2"
</ifModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^test$ wp-content/themes/mhspeakers.com/page-shop.php
</IfModule>

<IfModule mod_headers.c>

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"

#Sets Access Control
Header set Access-Control-Allow-Origin 'https://mhspeakers.com/homepage'
Header set Access-Control-Allow-Origin 'https://mhspeakers.com'
Header set Access-Control-Allow-Origin 'origin'

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

这是我没有 htaccess 重写的商店页面:
https ://mhspeakers.com/shop

如果我输入下面的链接,该链接旨在将我发送到我的 page-shop.php,但是我会得到一个白页。
https://mhspeakers.com/test

这些是我的 page-shop.php 文件的前几行:

<?php 
// Session Start 
session_start(); 

// Connect Handler
include('handler/connect.php'); ?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>MHSpeakers Shop</title>
        <meta name="viewport" content="width=device-width, intial-scale=1.0"/>
        <meta name="keywords" content="Cheshire's leading speaker designer and renovator.">
        <meta name="description" content="Cheshire's leading speaker designer and renovator. We buy, sell and build speakers.">
        <meta property="og:image" src="" alt="Cheshire's leading speaker designer and renovator."/>     
    </head>
 <?php get_header2(); ?>
<body>
    <div class="shop-page">
    <div class="shop-inner center">
    <h1 class="shop-h1">Shop</h1>
    ..................................

有什么建议么?

标签: phpapache.htaccessurl-rewriting

解决方案


推荐阅读