我想隐藏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仍显示
答案 0 :(得分:9)
尝试,它适合我!确保您在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]
答案 1 :(得分:4)
RewriteRule ^(.*)index\.(html|php)$ http://%{HTTP_HOST}/$1 [R=301,L]
答案 2 :(得分:0)
你可以像这样通过.htaccess重写'/index.php':
# Remove /index.php from all urls
RewriteRule ^(.+)/index\.php$ /$1 [R=302,L]