【问题标题】:Redirecting from an October / Laravel installation从十月 / Laravel 安装重定向
【发布时间】:2019-03-01 05:49:56
【问题描述】:

我有一个使用 October 构建的网站(基于 Laravel),并且 .htaccess 文件将所有请求都指向 index.php 页面,如预期的那样。我希望 www 根文件夹中有一个单独的目录指向一个博客,我将在其中安装一个 WordPress 实例。所以文件夹结构将如下所示:

www/
  .htaccess
  artisan
  index.php
  /blog <-- i want to install the WP blog here
  /bootstrap
  /config
  /modules
  /storage
  /themes
  /vendor

我尝试过重定向,但我对 .htaccess 不太擅长,并且不想因为出错而冒着网站停机的风险

有一堆 RewriteCond 语句使用 !阻止某些文件夹,然后使用标准 RewriteRule 过滤对 index.php 的请求

我想要在传入请求中检查 /blog 并绕过 index.php,将请求发送到我的 WP 安装所在的 /blog。

这是当前的 .htaccess(10 月 CMS 的默认设置)

<IfModule mod_rewrite.c>

    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    ##
    ## You may need to uncomment the following line for some hosting environments,
    ## if you have installed to a subdirectory, enter the name here also.
    ##
    # RewriteBase /

    ##
    ## Uncomment following lines to force HTTPS.
    ##
    # RewriteCond %{HTTPS} off
    # RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

    ##
    ## Black listed folders
    ##
    RewriteRule ^bootstrap/.* index.php [L,NC]
    RewriteRule ^config/.* index.php [L,NC]
    RewriteRule ^vendor/.* index.php [L,NC]
    RewriteRule ^storage/cms/.* index.php [L,NC]
    RewriteRule ^storage/logs/.* index.php [L,NC]
    RewriteRule ^storage/framework/.* index.php [L,NC]
    RewriteRule ^storage/temp/protected/.* index.php [L,NC]
    RewriteRule ^storage/app/uploads/protected/.* index.php [L,NC]

    ##
    ## White listed folders
    ##
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_FILENAME} !/.well-known/*
    RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/.*
    RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
    RewriteCond %{REQUEST_FILENAME} !/storage/temp/public/.*
    RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources)/.*
    RewriteCond %{REQUEST_FILENAME} !/plugins/.*/(assets|resources)/.*
    RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
    RewriteRule !^index.php index.php [L,NC]

    ##
    ## Block all PHP files, except index
    ##
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_FILENAME} \.php$
    RewriteRule !^index.php index.php [L,NC]

    ##
    ## Standard routes
    ##
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

谢谢,维特纳

【问题讨论】:

  • 您希望两个网站使用相同的域名吗?不适合使用 cookie 和会话变量
  • hmmm,没想到...在最后的分析中,我可能会使用 blog.thedomain.com 但这实际上是临时的,但感谢您的警告。

标签: wordpress laravel .htaccess octobercms


【解决方案1】:

如果您可以发布.htaccess 文件的问题区域,将会有所帮助。无论如何,请尝试在RewriteRule 重定向到index.php 的位置上方添加此RewriteCond

RewriteCond %{REQUEST_URI} !^/blog(.*)$

【讨论】:

  • 谢谢加里。我没有问题区域,例如 .htaccess 开箱即用。我只是想要一个单独处理/blog 的新规则。我现在要试试你的解决方案...
  • 不!仍然得到 404。我会将 .htaccess 的全部内容添加到原始帖子中,以便您查看当前的播放状态。
  • 使用它来工作:RewriteCond %{REQUEST_URI} "/blog/" RewriteRule (.*) $1 [L]
【解决方案2】:

您是否尝试过创建别名?

在您的 octoberCMS apache conf(位于 apache conf.d 目录中)中,您可以添加以下行:

Alias /blog /path/to/www/blog

【讨论】:

  • no joy :( 404 如果可以的话,我将简化我的 .htaccess,看看我是否可以在 10 月份停止在重定向之前抓取 url。那是那里的默认 .htaccess 文件,它看起来像对我来说有点“拥挤”。也许一个更简单的会更好......
猜你喜欢
  • 2017-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-13
  • 2018-01-07
  • 2018-04-22
  • 1970-01-01
  • 2021-08-06
相关资源
最近更新 更多