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



我写了一个.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上重定向到网上?

您不使用htaccess文件重定向到本地或服务器上的公用文件夹。您将域指向/public文件夹。

在cpanel中,添加域时,指定/public文件夹的路径作为要使用的域的路径。

将其用于根文件夹

<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';

最新更新