【问题标题】:Wordpress 404 without trailing slash没有斜杠的 Wordpress 404
【发布时间】:2012-02-05 21:03:53
【问题描述】:

我知道这可能已经得到解答,因为这似乎是一个常见问题,但我无法找到适合我的解决方案。

我在另一个站点的子目录中有一个 wordpress 站点。当我尝试调用 http://site.com/blog 时,我被重定向并出现 404 错误,但是当我调用 http://site.com/blog/ 时,页面按预期呈现。

不断出现的解决方案似乎是

# and does not end with a slash
RewriteCond %{REQUEST_URI} !/$
# then add a trailing slash and redirect
RewriteRule (.*) $1/ [R=301,L]

但每次我请求不带斜杠的页面时,我都会被重定向到http://site.com/app/webroot/blog

已安装博客的子文件夹位于 cakephp 应用程序的 webroot 中,我认为这可能与它有关?

【问题讨论】:

  • 只需在 htaccess 中添加 RewriteBase /blog
  • 谢谢,我已经在 wordpress 安装根目录中有这个

标签: wordpress .htaccess cakephp http-status-code-404


【解决方案1】:

我在网上搜索了更多信息后找到了answer

通过将它添加到根 .htaccess 中解决了我的问题

RewriteRule ^blog$ blog/ [L]

【讨论】:

    【解决方案2】:

    尝试将以下内容添加到 .htaccess 文件的顶部,就在 RewriteEngine On 下方。我假设 .htaccess 文件位于您网站的根目录中。

    #if this already exists, skip it, otherwise it should be before any other Rules
    RewriteEngine on
    #add this line to prevent your directory structure from showing up
    RewriteBase /
    

    【讨论】:

    • 为什么不直接使用RewriteBase /blog?似乎比创建另一个 .htaccess 文件更容易。
    • @Gerben 我的意思是将RewriteBase / 添加到我假设在根目录中的现有 htaccess 文件中。让我知道我的答案的哪一部分提出了其他建议,我会更正。谢谢
    • 他在/blog/ 安装了wordpress,所以我认为htaccess 位于/blog
    猜你喜欢
    • 2016-10-13
    • 1970-01-01
    • 2012-05-08
    • 2021-01-20
    • 1970-01-01
    • 2017-03-07
    • 2011-07-30
    • 2018-12-07
    • 2023-03-14
    相关资源
    最近更新 更多