【问题标题】:Website homepage to show subdirectory content via htaccess网站主页通过 htaccess 显示子目录内容
【发布时间】:2017-04-26 18:32:53
【问题描述】:

我有一个 Wordpress 网站,其 root 位于 http://www.example.com/web

通过 htaccess,当我访问该地址时,我想查看 http://www.example.com/web/about-me 上的内容,而浏览器仍显示 http://www.example.com/web

是否可以通过 .htaccess 来实现?我现在拥有的是

开始 WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php [L]
</IfModule>

结束 WordPress

我尝试在底部添加

RedirectMatch ^/$ /about-me/

没有任何成功。

【问题讨论】:

  • 让你所在的页面不显示在网址栏中?有趣的。我很想听听这个问题的答案。
  • 所以你想同时显示两个页面?我很困惑。请详细说明。
  • 李的回答清楚地说明了我想要做什么

标签: php wordpress apache .htaccess mod-rewrite


【解决方案1】:

所以基本上你有一个网站托管在你的域的子目录中,你想将主页 URL 重写到你的 about-me 页面,但用户看不到 URL 的变化。您的主要问题是尝试使用重定向来更改显示的 URL。

应该这样做

RewriteBase /web                      # Dropped the / suffix otherwise the rewrites get //
## RewriteRule ^index\.php$ - [L] -   # Removed because the Conditions below should be doing this?
RewriteRule ^$ /about-me [L]          # Redirect homepage
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]          # dropped the /web prefix as that is managed by the RewriteBase

结果:

【讨论】:

  • 我需要用 Wordpress 生成的 htaccess 替换它吗?因为如果我这样做,我会收到 500 服务器错误
  • 您应该能够简单地替换 htaccess 文件中的相关行。
  • 谢谢,您确实回答了我的问题,但我注意到我没有正确地提出问题。我认为这也适用于 Wordpress 多站点配置。基本上我有这个 .htaccess pastebin.com/tggD4kKX 并且我正在尝试设置它,以便当我转到根目录时,我会看到我的一个站点的主页位于子目录中(URL 没有改变)。如果你能看一看会很高兴。
猜你喜欢
  • 2018-08-27
  • 2016-07-29
  • 1970-01-01
  • 2012-11-24
  • 2014-03-25
  • 1970-01-01
  • 2020-08-18
  • 2018-01-05
  • 1970-01-01
相关资源
最近更新 更多