7

我想隐藏 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 仍然显示

4

3 回答 3

11

Try, It works for me! Make sure your have AllowOverride All set in httpd.conf

RewriteEngine On 

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

There is a regex issue in your rules, I have modified your rules and it works for me:

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]
于 2013-02-06T16:43:53.893 回答
6
RewriteRule ^(.*)index\.(html|php)$ http://%{HTTP_HOST}/$1 [R=301,L]
于 2014-07-15T05:30:12.170 回答
1

您可以像这样通过 .htaccess 重写“/index.php”:

# Remove /index.php from all urls
RewriteRule ^(.+)/index\.php$ /$1 [R=302,L]
于 2021-05-04T08:46:38.533 回答