【问题标题】:.htaccess removing index.php from URL.htaccess 从 URL 中删除 index.php
【发布时间】:2017-07-29 14:29:59
【问题描述】:

需要 htaccess/mod_rewrite 协助:

  1. 从显示网址中删除 index.php
  2. 将非 index.php url 重定向到它们各自的 index.php url,而不显示 index.php
  3. 有时候会有url没有index.php
  4. url 结构在域之后有子文件夹,在 index.php 之后有带有查询字符串的文件夹。尝试了所有答案,但没有奏效。

示例网址:
domain.com/index.php/moduleA/modeuleB?var=1&bvar=2
domain.com/folder/index.php/moduleC/moduleD?var=1&bvar=2
domain.com/folder/index.php/m1/m2/m3/m4/m5

【问题讨论】:

  • Tried all the answers but not working. 你尝试了什么?哪些答案?请展示你的努力。您希望写入的示例 URL 是什么?
  • "从显示 URL 中删除 index.php" - 你已经在你的应用程序中这样做了吗?

标签: php apache .htaccess redirect mod-rewrite


【解决方案1】:

把这个放到.htaccess文件中

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

【讨论】:

  • 不替换 index.php?网址保持不变。
  • 检查 mod_rewrite enable 如果不安装它会起作用
  • 我还能问一下额外的两个条件有什么意义吗?我们可以简单地将所有 index.php?/$1 重写为 $1
猜你喜欢
  • 2011-05-20
  • 2017-03-15
  • 2021-10-02
  • 2015-01-20
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 2013-05-15
相关资源
最近更新 更多