Url rewriting 如何允许WordPress和Laravel与htaccess共享顶级URL
编辑:这是对我的问题的主要编辑,基于评论中的反馈,以及对meta.stackoverflow的一些阅读 我已经改变了我的目标,现在我的首要任务是在Laravel和WP之间路由顶级URL:我不再寻求共享代码/数据库/用户信誉等 问题:要实现如下URL结构,我需要什么重写规则:Url rewriting 如何允许WordPress和Laravel与htaccess共享顶级URL,url-rewriting,.htaccess,Url Rewriting,.htaccess,编辑:这是对我的问题的主要编辑,基于评论中的反馈,以及对meta.stackoverflow的一些阅读 我已经改变了我的目标,现在我的首要任务是在Laravel和WP之间路由顶级URL:我不再寻求共享代码/数据库/用户信誉等 问题:要实现如下URL结构,我需要什么重写规则: / // (home) delivered by WP /content1 // WP /content(n) // WP /dashboard // delivered by Larave
/ // (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用户
- 我将完全分别管理这两个应用程序的演示文稿
/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>
重新编写引擎打开
重写条件%{HTTP_HOST}^www\.(.*)$[NC]
重写规则^(.*)$http://%1/$1[R=301,L]
#开始WordPress
重新启动发动机
重写基/
重写规则^widgets-[L]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
#拉维尔
重写规则^小部件-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$laravelindex.php/$1[L]
这样:
- 我可以访问我的WordPress页面
- WP为未知URL提供WP-404,但
- /widgets得到了一个普通的服务器404,而
- /laravel-index.php/widgets显示正确的内容
谢谢你的阅读 对于WordPress,您需要将不在小部件或仪表板文件夹中的所有请求发送到index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond !^widgets
RewriteCond !^dashboard
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
重写基/
重写秒^小部件
重写秒^仪表板
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
对于Laravel,您需要执行相反的操作,只将小部件或仪表板中的请求发送到Laravel-index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond !^widgets
RewriteCond !^dashboard
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Laravel
<IfModule mod_rewrite.c>
RewriteCond ^widgets
RewriteCond ^dashboard
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ laravel-index.php/$1 [L]
</IfModule>
#拉威尔
重写cond^widgets
重写COND^仪表板
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$laravelindex.php/$1[L]
@memeLab我很好奇当你抛弃WP时,你对Laravel使用了什么样的博客类型选项。以及您从现有WP数据进行的任何转换。您好@MECU,我选择了完全自定义的系统,因此我没有使用任何可用的composer捆绑包,并且没有现有数据,抱歉:)