【问题标题】:Rewrite index.html (default) but not index.php .htaccess重写 index.html(默认)但不是 index.php .htaccess
【发布时间】:2016-05-17 00:17:20
【问题描述】:

尽管我确信之前有人问过,但我并没有完全找到我需要的东西..

我需要将 index.html 重写为子目录,但允许访问 index.php。 我在根目录中有一个 Wordpress 安装程序,但只要它在 dev 中,我希望它能够被访问,如果直接使用确切路径寻址并且所有访问者编写域只被重定向。考虑并尝试使用 .htaccess 来做到这一点

Redirect /index.html http://www.example.com/home

但这也会将 index.php 重定向到子目录。 我也尝试添加

remove_filter('template_redirect', 'redirect_canonical'); 

到functions.php

接下来呢?

【问题讨论】:

  • 重定向不是重写——即使它实际上应该工作,所以我怀疑可能有另一个原因导致意外重定向。但是,是否有理由不使用 RewriteRule 而不是 Redirect? RewriteRule ^index\.html$ example.com/home 应该可以解决您的问题。如果它仍然与 index.php 混淆,那么它应该是您的应用程序中的其他内容。
  • 它不太奏效。它重写到错误页面“在此服务器上找不到请求的 URL /example.comi/home。”
  • 将它与 http:// 一起使用,所以没有让我修剪那部分。我现在放空间。 RewriteRule ^index\.html$ http://www.example.com/home
  • 它会重写为正确的子,但它仍然会重写其他所有内容。例如 index.php。但是如果我添加 wp-login.php 它实际上就在那里。但是我看不到前端。他们都被重写到子目录

标签: wordpress apache .htaccess mod-rewrite


【解决方案1】:

将以下代码放在根.htaccess文件中:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/home/
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)       /home/$1 [L,R=302]

上面的代码会将任何请求重定向到 /home/ 目录,包括主域并且只排除 index.php

例如,如果请求 site.com/page,它将转到 site.com/home/page

如果您请求 site.com,它会将您定向到 site.com/home/

但如果您请求 site.com/index.php,它将转到 site.com/index.php

【讨论】:

  • 好的,我会试试的。但是 [code] RewriteRule ^ /index.php [L,R=302] # 上面的行会将任何索引或 index.php 重定向到 index.php 听起来不像我要找的
  • 按原样尝试并告诉我,确保清空浏览器缓存
  • 它不像我想要的那样工作。如果我只写没有文件名的域/URL,则会出现一个空白页面。与 index.php 和所有 wordpress 页面相同。如果我把 index.html 也放在那里,它会按预期重定向到 example.com/home/
  • 缓存已清空。没有帮助
  • 所以你需要将每个 index.html 重定向到 spacific 目录吗?或者你的意思是只有当任何人请求 /dorectory/index.php 是 /directory/ ?
猜你喜欢
  • 1970-01-01
  • 2013-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-03
  • 2013-03-24
  • 1970-01-01
  • 2021-04-19
相关资源
最近更新 更多