【问题标题】:ModRewrite remove /index.php/Mod_Rewrite 删除 /index.php/
【发布时间】:2014-03-27 09:24:17
【问题描述】:

我有旧网址并想通过 .htaccess 删除 /index.php/:

所以旧网址是:

  www.mysite.com/index.php/onesite.html

将 .htaccess 中的改写成

 www.mysite.com/onesite.html

我该怎么做?

感谢您的帮助

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    将以下代码添加到您的 htaccess 将允许这样做

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^index.php/(.*)$ www.mysite.com/$1 [R=302,L]
    

    当您确定重定向正常工作时,将 302 更改为 301

    【讨论】:

      【解决方案2】:

      试试这个:

      RewriteRule ^index.php/(.*?)$ http://%{HTTP_HOST}/$1 [R=301,L]
      

      【讨论】:

      • 添加一些解释会很有用。
      【解决方案3】:

      只需将其添加到您的 .htaccess 中

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

      如果您的网站在子文件夹中,那么

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

      【讨论】:

        【解决方案4】:

        您可以在DOCUMENT_ROOT/.htaccess 文件中使用这两条规则:

        RewriteEngine On
        
        RewriteCond %{THE_REQUEST} /index\.php [NC]
        RewriteRule ^index\.php(/.*)?$ $1 [L,R=301,NC,NE]
        
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.+?)/?$ /index.php/$1 [L]
        

        【讨论】:

        • 这个 .htaccess 的位置是什么?您尝试了哪个 URL?
        猜你喜欢
        • 2011-08-10
        • 1970-01-01
        • 2012-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-09
        • 2011-07-09
        • 1970-01-01
        相关资源
        最近更新 更多