【问题标题】:Redirecting index.php to domain root only without any GET variables仅在没有任何 GET 变量的情况下将 index.php 重定向到域根目录
【发布时间】:2013-12-14 21:01:14
【问题描述】:

在我的网站www.apptic.me 上,我曾经有一个重定向规则,总是将 index.php 重定向到域根目录。

我意识到这使得底部的移动布局 herehere 丢失了 URL 的“index.php”部分,PHP 不再能够读取 GET 变量。

所以我删除了重定向。但是现在当用户导航到普通的旧www.apptic.me/index.php 时,“index.php”仍然存在。如果没有 GET 变量,我想将 index.php 重定向到根目录。

这可能吗?我该怎么做?

【问题讨论】:

  • 你的索引文件是什么?如我错了请纠正我。如果没有 $_GET 参数,您有一个要加载的 HTML 文件,如果 $_GET 不为空,则加载 index.php?
  • 你检查过html5boilerplate.com中的.htaccess文件吗?
  • 不,$_GET 参数只会导致加载不同的 CSS 文件和几个不同的标签。同一个文件。

标签: php regex apache .htaccess redirect


【解决方案1】:

将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php\s [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

【讨论】:

  • 这个具体有什么作用?
  • 这将在外部将每个http://domain.com/dir/index.php 重定向到http://domain.com/dir
【解决方案2】:

即使使用重定向,PHP 仍然可以读取 $_GET 变量,因此重定向不再有任何问题。

【讨论】:

    猜你喜欢
    • 2016-11-22
    • 2013-04-10
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    相关资源
    最近更新 更多