Wordpress 프로젝트 옆에 있는 Laravel 프로젝트(public_html 폴더에 있음)
public_html 폴더에 Laravel 프로젝트가 있습니다.도메인은 예를 들어 domain.com 내 .htaccess 파일(public_folder 내)은 다음과 같습니다.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
루트는 다음과 같습니다.
- api/capplate
- api/filename
- 인증/삭제
- 관리자/관리자
- 관리/요건
- 약속
- ...
URL의 예는 http://domain.com/appointment 입니다.
이제 domain.com에 워드프레스 웹사이트를 개설하고 싶습니다.domain.com에 접속하면 워드프레스 웹사이트가 나타납니다.하지만 저는 제 라라벨 프로젝트의 /예약과 같은 URL도 갖고 싶습니다.
가장 쉽고 깨끗한 방법은 무엇일까요?
Larabel 폴더의 Wordpress 공용 디렉터리에 대한 심볼 링크를 생성할 수 있습니다.예를들면,wp
:
/var
/www
/laravel
/public
/wp #(symlink to -> /var/www/wordpress/public_html)
index.php
.htaccess
/wordpress
/public_html
index.php
.htaccess
그리고 .htaccess의 Laravel 루트에 대해 설명하십시오.코드 예시/var/www/laravel/public/.htaccess
:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_FINISH} .
RewriteRule ^ - [L]
# Laravel
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !.*\.php$
RewriteRule ^(.*)$ $1 [E=FINISH:1,L]
RewriteCond %{REQUEST_URI} ^/(api/licenseplate)(\?.*|$) [OR]
RewriteCond %{REQUEST_URI} ^/(api/calendar)(\?.*|$) [OR]
RewriteCond %{REQUEST_URI} ^/(admin/settings)(\?.*|$) [OR]
RewriteCond %{REQUEST_URI} ^/(admin/appointments)(\?.*|$) [OR]
RewriteCond %{REQUEST_URI} ^/(appointment)(\?.*|$) [OR]
RewriteCond %{REQUEST_URI} ^/(auth/login)(\?.*|$)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [E=FINISH:1,L]
# Wordpress
RewriteCond %{REQUEST_URI} !^/wp
RewriteRule ^(.*)$ /wp/$1 [E=FINISH:1,L]
</IfModule>
코드 //var/www/wordpress/public_html/.htaccess
(wordpress .htaccess 복사만):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
서버 구조
.htaccess
파일을 사용하면 디렉토리 단위로 설정을 변경할 수 있습니다.즉, 요청을 가장 잘 처리하는 방법에 대한 규칙이 있는 디렉토리로 요청을 전송하기만 하면 됩니다.이렇게 하면.htaccess
Larabel과 WordPress 둘 다 디렉토리에 포함된 파일입니다.둘 다 보관되어 있는 부모 디렉토리에 대해 다른 디렉토리를 작성하기만 하면 됩니다.
다음 예시는 풀 패스가public_html
이/var/www/public_html
.
폴더 구조
/var/www/public_html/laravel
/var/www/public_html/wp
/var/www/public_buffic/.htaccess
# Limit Access To Laravel Public Folder
<Directory "/var/www/public_html/laravel">
Order Deny,allow
Deny from all
</Directory>
<Directory "/var/www/public_html/laravel/public">
Allow from all
</Directory>
# Rewrite Requests
<IfModule mod_rewrite.c>
RewriteEngine On
# Do Not Rewrite Directory And File Requests
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1 [L]
# Rewrite Laravel Routes
RewriteCond %{REQUEST_URI} api/licenseplate [OR]
RewriteCond %{REQUEST_URI} api/calendar [OR]
RewriteCond %{REQUEST_URI} admin/settings [OR]
RewriteCond %{REQUEST_URI} admin/appointments [OR]
RewriteCond %{REQUEST_URI} appointment [OR]
RewriteCond %{REQUEST_URI} auth/login
RewriteRule ^(.*)$ laravel/public/$1 [L]
# Rewrite To WordPress For Everything Else
RewriteRule ^(.*)$ wp/$1 [L]
</IfModule>
응용 프로그램 설정
Larabel과 WordPress는 모두 자산(이미지, CSS, JavaScript)에 대한 링크를 생성하는 방법을 가지고 있습니다.
WordPress는 하위 디렉터리에 쉽게 설치할 수 있도록 구축되어 있으므로 일반 설정 화면에서 WordPress 주소 및 사이트 주소만 변경하면 됩니다.
Laravel은 이 파일이 최상위 디렉토리에 설치되어 있다고 가정합니다.도우미는 자산 파일에 대한 경로를 생성하는 데 사용됩니다.따라서 기본 기능을 자신의 기능으로 재정의해야 합니다.방법은 다음과 같습니다.
만들다app/helpers.php
이런 내용으로
/**
* Generate an asset path for the application
* with the installation sub-directory
* prepended to the path.
*
* @param string $path
* @param bool $secure
* @return string
*/
function asset($path, $secure = null)
{
$path = ltrim($path, '/');
$dir = basename(dirname(__DIR__)) . '/public';
$url = app('url')->asset($path, $secure);
return str_replace($path, $dir . '/' . $path, $url);
}
더하다app/helpers.php
편집하여 자동 로드 프로세스로 이동composer.json
"autoload": {
//...
"files": [
"app/helpers.php"
]
},
명령줄 액세스 권한이 있는 경우 PHP Composer 업데이트
composer dump-autoload
여기 제가 비슷한 상황에 직면했을 때 취했던 방법이 있습니다.를 인스톨 합니다.wordpress
에public_html
전화번호부 및 가능한 한 저장해당 전화번호부탁드립니다.laravel application
WP 디렉토리로:WP 디렉토리:
wp-admin/
wp-content/
wp-includes/
... other wordpress files ...
app/ <-- laravel application
|-> app/
|-> bootstrap/
|-> config/
|-> public/
|-> ... other laravel files and directories ...
Now to get the 지금 바로 입수할 수 있는 것은
WordPress functions
available within your 사용 가능한Laravel application
, , include ,포함하다wp-load.php
within your 의 범위 내에서Laravel
installation and then you can use the 를 인스톨 하고 나서, 를 사용할 수 있습니다.enqueueing functions
부에서WordPress
필요한 자산을 로드합니다.
가장 좋은 방법은 Larabel 서비스 프로바이더 아키텍처를 따르는 것입니다.「」를 포함한 합니다.wp-load.php
를 사용합니다.boot function
:
// app/Providers/WordPressServiceProvider.php
class WordPressServiceProvider extends ServiceProvider {
protected $bootstrapFilePath = '../../wp-load.php'; // Adjust ur path
public function boot() {
// Load assets
wp_enqueue_style('app', '/app/public/app.css'); // Adjust ur path
}
public function register() {
// Load wordpress bootstrap file
if(File::exists($this->bootstrapFilePath)) {
require_once $this->bootstrapFilePath;
} else throw new \RuntimeException('WordPress Bootstrap file not found!');
}
}
앱 합니다.config/app.php:
/* ... */
'providers' => [
// ...
/*
* Application Service Providers...
*/
// ...
App\Providers\WordPressServiceProvider::class,
할 수 Larabel WordPress는 Larabel을 변경할 수 .views
예를 들어 다음과 같습니다.
{!! get_header() !!}
<div class="container">
<div class="content">
<div class="title">Laravel 5</div>
<div class="quote">{{ Inspiring::quote() }}</div>
</div>
</div>
{!! get_footer() !!}
는 워드 site should should should should should should should should should should should 에서 접속할 수 있어야 합니다.www.urdomain.com
url 앱 、 url 앱 、 。www.urdomain.com/app/appointment
을 시키다..htaccess
른른 URL 。이게 도움이 됐으면 좋겠다.
언급URL : https://stackoverflow.com/questions/38716585/laravel-project-next-to-wordpress-project-in-public-html-folder
'programing' 카테고리의 다른 글
스프링 부트엔티티 클래스에 옵션 전달 방법 <> (0) | 2023.03.29 |
---|---|
리액션이 포함된 쿠키 가져오기 (0) | 2023.03.29 |
쉼표를 사용하여 NSString을 분할합니다. (0) | 2023.03.29 |
Base64는 Javascript 객체를 인코딩합니다. (0) | 2023.03.29 |
포스트그레스 집약함수에서의 DISIGNITY ON (0) | 2023.03.19 |