Larabel 5 – URL에서 공개 삭제
이것이 매우 인기 있는 질문인 것은 알고 있습니다만, 아직 Larabel 5에 대한 유효한 솔루션을 찾을 수 없습니다.코드 시그니터에서 오랫동안 이주를 시도했지만, 이 복잡한 설치 과정 때문에 계속 지연되고 있습니다.
VM을 실행하고 싶지 않습니다.프로젝트 간에 전환할 때는 이 작업이 어색할 뿐입니다.
문서 루트를 공용 폴더로 설정하고 싶지 않습니다. 프로젝트 간에 전환할 때도 이 작업이 어색합니다.
.htaccess mod_rewrite 메서드를 사용해 보았습니다.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
컴파일된 Larabel NotFoundHttpException만 표시됩니다.php 행 7610.
얼마 전 L4를 시도했을 때 공용 폴더의 내용을 루트로 이동하는 방법을 사용했습니다.L5의 구조는 매우 다르며, 같은 순서로 Larabel이 완전히 망가졌습니다(서버는 빈 페이지만 반환합니다).
개발 환경에서 '공공'을 제거하는 적절한 방법이 있습니까?
- L5와 연동
- 프로젝트를 쉽게 전환할 수 있습니다(보통 한 번에 2개 또는 3개를 작업하고 있습니다).
감사해요.
** MAMP와 PHP 5.6.2를 사용하고 있습니다.
Larabel 5의 경우:
- " " " " "
server.php
에서 Laravel로 이동합니다.index.php
.htaccess
/public
라라벨
바로 그거야!
Docker와 함께 Laravel 프로젝트를 진행할 때 주의해 주십시오.이러한 작업은 필요 없습니다.이 옵션은 루트(또는 보다 일반적으로:public_html
웹 사이트의 디렉토리는 Laravel 프로젝트입니다(Docker를 사용하는 경우는 해당되지 않습니다).
하지마!
이름을 바꾸면 안 됩니다.server.php
에서 Laravel로 이동합니다.index.php
해 주세요..htaccess
/public
라라벨 ★★★★★★★★★★★★★★★★★★★!!!
모든 수 ..env
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★직접 해보세요.넌 그걸 원하지 않아!
하다
Catalyst-Manager를 ..htaccess
하다
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
, 베이스 가 사일런트하게 「URI」, 「URI」로 씁니다./public
폴더입니다.HTTP Authorization Header 등의 모든 헤더와 옵션의 모든 URI 파라미터는 자동으로 에 전달됩니다./public
폴더도 사용할 수 있습니다.
다음 두 가지 답변을 사용하여 문제를 해결했습니다.
- 서버의 이름을 변경합니다.php to index.displaces (변경 없음)
- .htaccess를 공용 폴더에서 루트 폴더로 복사합니다(아래에 설명된 rimon.ekjon 등).
.htaccess를 변경하면 다음과 같이 statics에 액세스 할 수 있습니다.
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^/public/ RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
다른 정적 파일이 필요한 경우 이전에 선언한 목록에 확장자를 추가하십시오.
Larabel 5.5에서는 루트 디렉토리에 .htacess 파일을 생성하여 다음 코드를 배치합니다.- 참조 링크
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</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
</IfModule>
.htaccess
root 디렉토리에 파일을 저장하고 다음과 같은 플레이스 코드를 지정합니다.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</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
</IfModule>
5단계 URL에서 공개를 쉽게 삭제할 수 있습니다.index.php 및 .htaccess를 퍼블릭디렉토리에서 잘라내 루트디렉토리에 붙여넣고, index.php 의 2 행을 모두 치환하기만 하면 됩니다.
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
주의: 위의 방법은 가상 호스트를 셋업할 때 문제가 발생할 수 있으므로 초보자만을 위한 것입니다.최적의 해결책은 로컬머신에 가상 호스트를 셋업하여 프로젝트의 퍼블릭디렉토리를 포인트 하는 것입니다.
@rimon.ekjon :
서버의 이름을 변경합니다.Larabel 루트 폴더에 있는 php를 index.php로 전송하고 /public 디렉토리에서 Larabel 루트 폴더로 .htaccess 파일을 복사합니다. -- That it ! : )
난 그게 효과가 있어.그러나 asset() helper를 사용했기 때문에 /public 디렉토리의 모든 리소스 파일을 찾을 수 없고 URL을 요청할 수 없었습니다.
다음과 같이 /Iluminate/Foundation/helpers.php/asset() 함수를 변경했습니다.
function asset($path, $secure = null)
{
return app('url')->asset("public/".$path, $secure);
}
이것으로 모든 것이 동작합니다. : )
@rimon.ekjon과 여러분 모두에게 감사드립니다.
2020년 작성자 업데이트
이 답변은 권장되지 않습니다." " " 를 처리합니다..htaccess
파일을 권장합니다.
루트에 .htaccess 파일을 만들고 이 행을 추가합니다.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
바로 그거야!
위의 코드는 root public_html 폴더에서 작동합니다.코어 라라벨 파일이 public_html 폴더 안에 있어야 한다고 했지만 디렉토리가 public_html/laravelapp/public처럼 보이고 위의 코드를 laravelapp 안에 넣으면 작동하지 않습니다.따라서 모든 코어 파일을 public_html에 복사하고 .htaccess 파일을 저장해야 합니다.
코드를 서브디렉토리에 보존하고 싶은 경우는, 서브 도메인을 작성할 수 있습니다.이 코드는 서브 디렉토리에서도 사용할 수 있습니다.
1) L5에서 퍼블릭디렉토리를 이동하기 위한 작업방법을 찾지 못했습니다.부트스트랩에서 몇 가지 사항을 수정할 수 있지만index.php
퍼블릭 디렉토리가 존재하는 것을 전제로 한 도우미 기능이 몇 가지 있는 것 같습니다.솔직히 말해서 당신은 공공 디렉토리를 옮기면 안 돼요.
2) MAMP를 사용하는 경우 프로젝트별로 퍼블릭디렉토리를 투영하는 새로운 vhost를 작성해야 합니다.생성 후 정의된 서버 이름으로 다음과 같이 각 프로젝트에 액세스합니다.
http://project1.dev
http://project2.dev
laravel5에서 공개 URL을 삭제할 수 있습니다.다음의 순서에 따릅니다.
스텝 1. 퍼블릭에서 모든 파일을 복사하여 루트 디렉토리에 붙여넣기
2. 2. 열기index.php
replace 일 file
require __DIR__.'/../bootstrap/autoload.php';
로.
require __DIR__.'/bootstrap/autoload.php';
그리고.
$app = require_once __DIR__.'/../bootstrap/app.php';
로.
$app = require_once __DIR__.'/bootstrap/app.php';
그리고 모든 캐시와 쿠키를 제거합니다.
URL에서 공개를 삭제하는 4가지 가장 좋은 방법.
같은 방법으로 URL에서 공용을 삭제한 경우 서버 이름을 변경합니다.php를 index.filename으로 변환하여 코어 파일 경로로 변경합니다.분명히, 그렇게 하지 마세요.그럼 왜 라라벨은 이런 식으로 해결책을 제시하지 않는 거죠? 그건 적절한 방법이 아니니까요.
1) Larabel에서 htaccess를 사용하여 URL에서 공개 삭제
루트에 .htaccess 파일을 추가하면 공개 없이 웹 사이트에 액세스할 수 있습니다.
<ifmodule mod_rewrite.c>
<ifmodule mod_negotiation.c>
Options -MultiViews
</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
</ifmodule>
2) 로컬에 가상 호스트를 생성하여 공개를 삭제합니다.
여기서 Window 운영체제에 대한 데모를 하고 있습니다.하지만 누구나 쉽게 따라갈 수 있도록 단계를 정의하도록 노력하겠습니다.또한 특정 운영 체제에 대한 동일한 Google을 검색할 수도 있습니다.
1단계: C로 이동합니다.\Windows\system32\drivers\etc\는 "hosts" 파일을 Administrator 모드로 엽니다.
2단계: 다음 코드를 추가합니다.여기 projectname.local 도메인 이름 데모 데모를 보내드리겠습니다. 원하는 데모를 지정할 수 있습니다.모든 장소에서 일정하게 유지하세요.
127.0.0.1 projectname.local
3단계: 다음으로 넘어갑니다.C:\xampp\apache\conf\extra
및 xampp " " wamp " " ""C:\wamp\bin\apache\Apache2.4.4\conf\extra"
수 있습니다."httpd-vhosts.conf"
파일에 다음 코드를 추가합니다.
주의:프로젝트에 따라 문서 루트를 변경하고 "호스트" 파일에 정의하면서 도메인 이름도 추가합니다.
<VirtualHost projectname.local>
ServerAdmin projectname.local
DocumentRoot "C:/xampp/htdocs/projectdir"
ServerName projectname.local
ErrorLog "logs/projectname.local.log"
CustomLog "logs/projectname.local.log" common
</VirtualHost>
스텝 4: 마지막이지만 중요한 스텝은 Xampp 또는 Wamp를 재시작하여 같은 URL에 접속하면 Larabel은 공개 URL 없이 응답합니다.
3) Larabel에서 명령어를 실행하여 공개를 삭제합니다.
로컬에서 작업하는 경우 터미널 또는 명령줄 도구에서 다음 명령을 실행하기 위해 필요한 작업을 수행할 필요가 없습니다.그 후 명령줄에 URL을 입력하여 웹사이트에 접속할 수 있습니다.
> php artisan serve
특정 IP에서 프로젝트를 실행하려면 다음 명령을 실행해야 합니다.LAN에서 작업하는 경우 로컬에서 다른 사용자가 웹 사이트에 액세스할 수 있도록 허용하려면 명령어 뒤에 IP 주소를 실행한 후 "ipconfig"를 실행하여 IP 주소를 확인해야 합니다.
> php artisan serve --host=192.168.0.177
특정 포트를 사용하여 특정 IP에서 프로젝트를 실행하려면 다음 명령을 수행해야 합니다.
> php artisan serve --host=192.168.0.177 --port=77
4) 호스트 서버 또는 cpanel 상의 퍼블릭 삭제
프로젝트가 완료된 후 서버에서 프로젝트를 호스트해야 합니다. 그런 다음 도메인의 문서 루트를 공용 폴더로 설정하기만 하면 됩니다.다음 스크린샷을 확인하십시오.
를 public_html과 같이 ."public_html/public"
.
여기서 인용한 레퍼런스
다음은 2018년 5월 현재 Laravel 5.5에 적합한 가장 최단 솔루션입니다.
좀 해라
.htaccess
/public 디렉토리에서 root 디렉토리로 파일을 전송하고 내용을 다음 코드로 바꿉니다.<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ server.php [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^/public/ RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC] </IfModule>
해 두세요.
.htaccess
파일만 있으면 됩니다.을 " " " "로 변경합니다.
server.php
index.php
그게 다 즐거움이야기!
다른 모든 파일과 디렉토리를 'locale'이라는 이름의 폴더에 저장했다고 가정해 보겠습니다.
index.php로 이동하여 다음 두 줄을 찾습니다.
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
다음과 같이 변경합니다.
require __DIR__.'/locale/bootstrap/autoload.php';
$app = require_once __DIR__.'/locale/bootstrap/app.php';
베스트 어프로치:공용 삭제는 권장하지 않습니다.on local computer create a virtual host point to public directory
★★★★★★★★★★★★★★★★★」on remote hosting change public to public_html and point your domain to this directory
디렉토리의 가 안전합니다. :) Larabel 코드:)
방법 1:
이름만 바꿨어요.server.php
로로 합니다.index.php
가 있다
방법 2:.
이것은 모든 라라벨 버전에서 잘 작동합니다.
여기 내 디렉토리 구조가 있습니다.
/laravel/
... app
... bootstrap
... public
... etc
다음의 간단한 순서를 실행해 주세요.
- 모든 파일을 공용 디렉토리에서 루트 /laravel/로 이동합니다.
- 퍼블릭 디렉토리가 필요 없기 때문에 옵션으로 지금 삭제할 수 있습니다.
- 이제 index.displaces를 열고 다음 치환을 수행합니다.
DIR.'/../bootstrap/autoload가 필요합니다.php';
로.
DIR.'/bootstrap/autoload가 필요합니다.php';
그리고.
$app = require_once DIR.'/../bootstrap/start.php';
로.
$app = require_once DIR.'/bootstrap/start.php';
- 이제 bootstrap/bootstrap.display를 열고 공용 디렉토리 경로를 변경합니다.
'public' => DIR', /../public',
로.
'public' => DIR'/..',
이것으로 끝입니다.http:// localhost/laravel/ 를 사용해 주세요.
@Humble Learner에 추가하고 자산의 URL 경로를 수정하는 적절한 위치는 /Iluminate/Routing/UrlGenerator.php/asset()입니다.
일치시킬 메서드를 업데이트합니다.
public function asset($path, $secure = null)
{
if ($this->isValidUrl($path)) return $path;
$root = $this->getRootUrl($this->getScheme($secure));
return $this->removeIndex($root).'/public/'.trim($path, '/');
}
그러면 스크립트, 스타일 및 이미지 경로가 수정됩니다.자산 경로를 위한 모든 것.
XAMPP 사용자가 larabel 기본 파일 시스템을 건드리지 않고 URL에서 공용을 삭제하는 경우 응용 프로그램에서 이 작업을 수행하도록 가상 호스트를 설정합니다.
XAMPP 제어판 응용 프로그램을 열고 Apache를 중지합니다.최신 Windows 머신에서는 서비스로 실행할 수 있으므로 Apache 모듈 왼쪽에 있는 체크박스를 켜십시오.
를 해 .
C:/xampp/apache/conf/extra
XAMPP를 사용하다텍스트 편집기를 사용하여 httpd-vhosts.conf 파일을 엽니다.
에서 19번을 찾아보세요.
NameVirtualHost *:80
해시를 언코멘트 또는 삭제합니다.파일 맨 아래에 다음 코드를 붙여넣습니다.
<VirtualHost *>
ServerAdmin admin@localhost.com
DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
ServerName localhost
ServerAlias localhost
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
- 이제 아래 코드를 복사하여 붙여넣기하여 가상 호스트 디렉토리를 추가할 수 있습니다.예를 들어 Eathery Engine이라는 사이트에서 작업하고 있기 때문에 다음 스니펫을 사용하여 로컬 설치에서 하위 도메인을 작업할 수 있습니다.
<VirtualHost eateryengine.dev>
ServerAdmin admin@localhost.com
DocumentRoot "C:/xampp/htdocs/eateryengine" # change this line with your htdocs folder
ServerName eateryengine.dev
ServerAlias eateryengine.dev
<Directory "C:/xampp/htdocs/eateryengine">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
- 이 파일은 Windows HOSTS에 .이 파일은 다음 위치에 있습니다.
C:/Windows/System32/drivers/etc/hosts
호스트메모장으로 엽니다. - #localhost 이름 해결은 DNS 자체 내에서 처리됩니다.
127.0.0.1 localhost
localhost 이름 해결은 DNS 자체 내에서 처리됩니다.
127.0.0.1 localhost
127.0.0.1 eateryengine.dev #change to match your Virtual Host.
127.0.0.1 demo.eateryengine.dev #manually add new sub-domains.
- Apache를 재시작하고 모든 것을 테스트합니다.
원본 기사는 여기에서 찾을 수 있습니다.
Laravel 설정에는 항상 공용 폴더가 있어야 하는 이유가 있습니다.모든 공용 관련 항목이 공용 폴더 내에 있어야 합니다.
IP 주소/도메인은 Larabel 루트 폴더를 가리키지 말고 공용 폴더를 가리킵니다. 하는 것은 하지 않습니다.는 "IP"에 한 하지 않기 입니다.이는 사용자가 제한사항을 작성하지 않는 한입니다.
.htaccess
할 수 있습니다. , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , .
「은 「재작성 조건」에 해 주세요..htaccess
module을 가 해결됩니다.
" " 라는 이름의 새 ..htaccess
.
<IfModule mod_rewrite.c>
#Session timeout
<IfModule mod_negotiation.c>
Options -MultiViews
</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
</IfModule>
: 을 변경한 : " " " " ]server.php
로로 합니다.index.php
.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
mod_rewrite 모듈을 활성화합니다.
sudo a2enmod rewrite
Apache를 재시작합니다.
sudo service apache2 restart
.htaccess 파일 내에서 mod_rewrite를 사용하려면(이것은 매우 일반적인 사용 예)를 사용하여
sudo nano /etc/apache2/sites-available/000-default.conf
DocumentRoot /var/www/html 아래에 다음 행을 추가합니다.
<Directory "/var/www/html">
AllowOverride All
</Directory>
서버를 재기동합니다.
sudo service apache2 restart
문제는 /public을 입력해도 URL에서 사용할 수 있기 때문에 public/index.php에 배치해야 하는 수정을 작성했습니다.
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
if(stristr($uri, '/public/') == TRUE) {
if(file_exists(__DIR__.'/public'.$uri)){
}else{
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$actual_link = str_replace('public/', '',$actual_link);
header("HTTP/1.0 404 Not Found");
header("Location: ".$actual_link."");
exit();
return false;
}}
이 코드 평화는 URL에서 공개를 삭제하고 404를 부여한 후 공개 없이 URL로 리다이렉트합니다.
나는 그것이 이 문제에 대한 많은 해결책이라는 것을 안다.루트 디렉터리에 .htaccess 파일을 추가하는 것이 가장 쉽고 최선의 해결책입니다.
저는 이 문제에 대해 우리가 제공한 답변을 시도했습니다만, Laravel의 auth:api guard에 관한 몇 가지 문제에 직면했습니다.
최신 솔루션은 다음과 같습니다.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
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
</IfModule>
루트 디렉토리에 .htaccess 파일을 만들고 이 코드를 추가합니다.그리고 모든 것이 잘 되어 간다.
루트 디렉토리에 .htaccess 파일을 생성하여 다음과 같은 코드를 배치합니다.
<IfModule mod_rewrite.c>
#Session timeout
<IfModule mod_negotiation.c>
Options -MultiViews
</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
</IfModule>
/public 디렉토리에 .htaccess 파일을 생성하여 다음과 같은 코드를 배치합니다.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
루트 DIR에 .htaccess 파일을 만들고 다음 코드를 붙여넣습니다.이상입니다.p
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
루트 폴더에 Larabel을 배치하는 것을 추천하지 않아도 피할 수 없는 경우가 있습니다.이 경우 위의 방법이 자산에 적용되지 않기 때문에 htaccess 변경: 서버 복사 후 신속하게 수정했습니다.php to index.htaccess 파일을 다음과 같이 편집합니다.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
### fix file rewrites on root path ###
#select file url
RewriteCond %{REQUEST_URI} ^(.*)$
#if file exists in /public/<filename>
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
#redirect to /public/<filename>
RewriteRule ^(.*)$ public/$1 [L]
###############
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
#RewriteCond %{REQUEST_FILENAME} -d # comment this rules or the user will read non-public file and folders!
#RewriteCond %{REQUEST_FILENAME} -f #
RewriteRule ^ index.php [L]
</IfModule>
이것은 신속한 수정을 필요로 했기 때문에, 누구라도 업그레이드에 응할 수 있습니다.
라라벨 5.5
Larabel을 처음 설치한 후, 저는 유명한 "퍼블릭 폴더 문제"에 직면했고, 제 개인적인 의견으로는 웹에서 발견된 다른 문제보다 "깨끗한" 해결책을 생각해 냈습니다.
성과
public
, URI의 " " " "- 의호를
.env
많은 사람을
..htaccess
를 사용합니다.mod_rewrite
네 가지 간단한 규칙이 있습니다.
순서
.htaccess
public/.htaccess
- 아래와 같이 편집해 주세요.
한 도 안 좋겠습니다)mod_rewrite
룰을 이해하기 는, 로 이 「Laravel」에 되어 있는 「Laravel」에 접속되어 있는 것을 .https://example.com
,https://example.com/index.php
로딩되어 있습니다.되어 있습니다.header("refresh: 5; https://example.com/public/")
, 、 , , , , , , , ,로 .https://example.com/public/index.php
이 두 번째 ★★★★★★★★★★★★★★★★★★★」index.php
컨트롤러와 다른 것들을 로드하는 책임이 있습니다.
# IfModule prevents the server error if the app is moved in an environment which doesn’t support mod_rewrite
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# RULES ORIGINALLY IN public/.htaccess ---
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# --- END
# PERSONAL RULES ---
# All the requests on port 80 are redirected on HTTPS
RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# When .env file is requested, server redirects to 404
RewriteRule ^\.env$ - [R=404,L,NC]
# If the REQUEST_URI is empty (means: http://example.com), it loads /public/index.php
# N.B.: REQUEST_URI is *never* actually empty, it contains a slash that must be set as match as below
# .* means: anything can go here at least 0 times (= accepts any sequence of characters, including an empty string)
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*) /public/index.php [L]
# If the current request is asking for a REQUEST_FILENAME that:
# a) !== existent directory
# b) !== existent file
# => if URI !== css||js||images/whatever => server loads /public/index.php, which is responsible to load the app and the related controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^(css|js|images|media)/(.*)$ /public/index.php [L,NC]
# If the current request is asking for a REQUEST_FILENAME that:
# a) !== existent directory
# b) !== existent file
# => if URI == css||js||images[=$1]/whatever[=$2] => server loads the resource at public/$1/$2
# If R flag is added, the server not only loads the resource at public/$1/$2 but redirects to it
# e.g.: bamboo.jpg resides in example.com/public/media/bamboo.jpg
# Client asks for example.com/media/bamboo.jpg
# Without R flag: the URI remains example.com/media/bamboo.jpg and loads the image
# With R flag: the server redirects the client to example.com/public/media/bamboo.jpg and loads the image
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(css|js|images|media)/(.*)$ /public/$1/$2 [L,NC]
# --- END
</IfModule>
규칙는 음음원원(원원)입니다).public/.htaccess
할 수 는 삭제할 수 있습니다.같은 규칙이, 사실, 마지막 두 규칙에서 더 자세히 설명되었습니다.
# Handle Front Controller...
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^ index.php [L]
편집: 나는 Abhinav Saraswat의 해결책을 놓쳤고 그의 대답은 받아들여진 것이어야 한다.파일을 수정하지 않고 모든 트래픽을 공용 폴더로 리디렉션하는 단순하고 명확한 규칙 하나만 있습니다.
먼저 이 단계를 사용할 수 있습니다.
Larabel 5의 경우:
1. 서버의 이름을 변경합니다.index.php에 대한 Larabel 루트 폴더의 php
2. /public 디렉토리에서 Larabel 루트 폴더에 .htaccess 파일을 복사합니다.
출처 : https://stackoverflow.com/a/28735930
다음 절차를 수행한 후에는 모든 css 및 스크립트 경로를 변경해야 하는데, 이는 매우 피곤합니다.
솔루션 제안: 간단한 변경으로helpers::asset
★★★★★★ 。
이 경우:
vendor\laravel\framework\src\Illuminate\Foundation\helpers.php
고토 선 130
를 쓰다
"public/".$path
$path
,function asset($path, $secure = null){ return app('url')->asset("public/".$path, $secure); }
전에 몇 가지 기사를 읽었는데 잘 작동하고 있지만 안전한지 아닌지 정말 모르겠다.
a. Create new folder local.
b. Move all project into the local folder expect public folder.
c. Move all the content of public folder to project root.
d. Delete the blank public folder
f. Edit the index file.
index.php를 편집합니다.
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
로.
require __DIR__.'/local/bootstrap/autoload.php';
$app = require_once __DIR__.'/local/bootstrap/app.php';
또 다른 방법은 htdocs 또는 www 등의 ln 명령어를 사용하여 심볼릭 링크(Linux에서는 Win에 대해 알 수 없음)를 작성하는 것입니다. ln projectname/public project
이 localhost/ localhost/localhost를 통해 액세스할 수 .
다양한 방법을 사용하여 url에서 public 키워드를 삭제할 수 있습니다.
1) 전용 호스팅을 사용하고 루트 액세스 권한이 있는 경우 가상 호스트를 사용하여 url에서 public 키워드를 삭제할 수 있습니다.DocumentRoot 경로를 public과 함께 지정해야 합니다.따라서 공개 디렉토리에서 인덱스를 시작하고 URL에서 인덱스를 제거합니다.
<VirtualHost *:80>
ServerAdmin info@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/{yoursourcedirectory}/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
2) 호스트 루트 액세스 권한이 없는 경우 루트 디렉토리에 새로운 .htaccess 파일을 생성하여 다음과 같이 코드를 입력합니다.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</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
</IfModule>
여기에서 더 많은 참고 자료를 얻을 수 있습니다.
나는 이 문제에 대한 가장 효과적인 해결책을 찾았다.
만 하면 돼요..htaccess
root 폴더에 저장하고 다음 코드를 작성합니다.기타 필요 없음
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
<IfModule php7_module>
php_flag display_errors Off
php_value max_execution_time 30
php_value max_input_time 60
php_value max_input_vars 1000
php_value memory_limit -1
php_value post_max_size 8M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php71"
php_value upload_max_filesize 2M
php_flag zlib.output_compression Off
</IfModule>
언급URL : https://stackoverflow.com/questions/28364496/laravel-5-remove-public-from-url
'itsource' 카테고리의 다른 글
MySQL에서 날짜/시간에서 시간을 빼는 방법 (0) | 2022.11.14 |
---|---|
PHP에서 시간대를 지정하여 현재 날짜를 가져오시겠습니까? (0) | 2022.11.14 |
파일 확장자는 어떻게 확인할 수 있나요? (0) | 2022.11.14 |
RegExp를 사용하는 문자열에서 SQL 추출 패턴 (0) | 2022.11.14 |
in_array 다중값 (0) | 2022.11.14 |