编辑: 基于评论和meta.stackoverflow的反馈以及一些阅读,我对我的问题进行了重大修改。
我已经调整了我的目标,现在我的首要任务是在Laravel和WP之间路由顶级URL:我不再寻求共享代码/数据库/用户凭据等。
问题:为实现以下URL结构,我需要哪些重写规则:
/ // (home) delivered by WP
/content1 // WP
/content(n) // WP
/dashboard // delivered by Laravel
/widgets/mywidget/ // Laravel
- 所有的Laravel页面将位于/admin或/widgets,其他所有内容都将由WordPress处理,包括404页面。
- 我将完全分离WP和Laravel。
- 我的同事和我将使用管理账户编辑WP,不会有其他WP用户。
- 我将完全独立地管理这两个应用程序的展示。
我已经按照以下方式设置了我的文件,并测试了每个应用程序可以独立运行。(例如,如果Laravel的重写规则是唯一在使用的,则使用laravel-index.php时,Laravel可以正常工作)
从网站根目录开始:public_html/
/wordpress
/laravel3 // app dir
/css // these are from the laravel public dir
/images //
/js, etc //
/index.php // WP index.php
/laravel-index.php // laravel's index.php
我在一个共享托管环境中,没有访问httpd.conf的权限。
这是我的.htaccess文件
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^widgets - [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Laravel
<IfModule mod_rewrite.c>
RewriteRule !^widgets - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ laravel-index.php/$1 [L]
</IfModule>
这样做:
- 我可以访问我的WordPress页面,
- WP为未知的URL提供WP-404,但是
- /widgets得到了一个普通的服务器404,而
- /laravel-index.php/widgets显示了正确的内容。
另外一个问题是WP仪表板正在窃取对/dashboard的请求,我想将其重定向到Laravel
谢谢阅读!