【问题标题】:.htaccess redirect index.php to /.htaccess 将 index.php 重定向到 /
【发布时间】:2013-01-21 22:35:47
【问题描述】:

我想隐藏 index.php 页面,只显示域。

.htaccess 可以做到这一点吗?

RewriteRule ^index\.php/?$ / [L,R=301,NC]

也试过了:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.php HTTP/
RewriteRule ^index.php$ http://example.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

index.php 仍然显示

【问题讨论】:

    标签: linux apache .htaccess redirect mod-fcgid


    【解决方案1】:

    试试吧,它对我有用!确保您在 httpd.conf 中设置了 AllowOverride All

    RewriteEngine On 
    
        RewriteCond %{REQUEST_URI} index\.php
        RewriteRule ^(.*)index\.php$ /$1/ [R=301,L]
    

    您的规则中有一个正则表达式问题,我已经修改了您的规则,它适用于我:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} index\.php
    RewriteRule ^index\.php$ http://example\.com/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index\.php [L]
    

    【讨论】:

    • 不。浏览器是否可以始终显示 index.php 而不仅仅是重定向到域?
    • 你能发布你的 .htaccess 文件吗?
    • 重定向正常,但还添加了斜杠,结果是example.com//而不是example.com
    【解决方案2】:
    RewriteRule ^(.*)index\.(html|php)$ http://%{HTTP_HOST}/$1 [R=301,L]
    

    【讨论】:

      【解决方案3】:

      你可以像这样通过.htaccess 重写'/index.php':

      # Remove /index.php from all urls
      RewriteRule ^(.+)/index\.php$ /$1 [R=302,L]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-08-31
        • 1970-01-01
        • 2011-12-13
        • 2014-10-17
        • 2012-04-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多