如何让.htaccess文件重定向到cPanel PHP上的公共文件夹

yrdbyhpb  于 2022-11-16  发布在  PHP
关注(0)|答案(2)|浏览(163)

我编写了一个.htaccess文件,该文件重定向到我本地计算机上的公共文件夹,但在上载到服务器后,该文件并没有重定向到我的Cpanel上。

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} !/public
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d

# Direct all requests to /public folder
RewriteRule ^(.*)$ /public/index.php?url=$1 [L]
</IfModule>

如何在我的Cpanel上在线重定向?

xkrw2x1b

xkrw2x1b1#

不要使用htaccess文件来重定向到本地或服务器上的公共文件夹,而是将域指向/public文件夹。
在cpanel中,添加域时,您可以指定/public文件夹的路径作为要使用的域的路径。

5uzkadbs

5uzkadbs2#

使用此文件夹到根文件夹

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]

RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php

#caching
<FilesMatch ".(jpg|jpeg|png|gif|swf)$">
<IfModule mod_headers.c>
    Header set Cache-Control "max-age=604800, public"
</IfModule>
</FilesMatch>

<FilesMatch ".(xml|txt|css|js)$">
<IfModule mod_headers.c>
    Header set Cache-Control "max-age=604800, proxy-revalidate"
</IfModule>
</FilesMatch>

然后创建另一个名为server.php的文件
将此代码放到server.php中

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

相关问题