【问题标题】:Able to remove .php extension but can't index.php from php mvc url pattern能够删除 .php 扩展名但不能从 php mvc url 模式中删除 index.php
【发布时间】:2016-07-11 07:06:55
【问题描述】:

我可以从我的 URL 中删除 .php,但不能在 php mvc 框架中删除 index.php。实际上我需要 /app/className/action 而不是 /index.php/app/className/action

我的.htaccess文件结构如下,

Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
</IfModule>

此规则返回 /index/app/className/action 而不是 /app/className/action

提前感谢您的帮助。

【问题讨论】:

    标签: php .htaccess model-view-controller


    【解决方案1】:

    要删除index.php,您可以使用以下规则:

    Options +FollowSymLinks -MultiViews
    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /
      #Redirect /index.php/foobar to /foobar
       RewriteCond %{THE_REQUEST} /index\.php/.+ [NC]
       RewriteRule ^index.php/(.+)$ /$1 [L,R]
       #internally map /foobar back to /index.php/foobar
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      试试这个

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-08-27
        • 1970-01-01
        • 1970-01-01
        • 2022-01-21
        • 2013-07-24
        • 2020-08-11
        相关资源
        最近更新 更多