Linux .htaccess 将 index.php 重定向到 /
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14733988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.htaccess redirect index.php to /
提问by Nikki Wilson
I would like to hide the index.php page and just show the domain.
我想隐藏 index.php 页面并只显示域。
Is this possible with .htaccess?
.htaccess 可以实现吗?
RewriteRule ^index\.php/?$ / [L,R=301,NC]
Also tried:
还试过:
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 still shows
index.php 仍然显示
回答by Satish
Try, It works for me! Make sure your have AllowOverride All
set in httpd.conf
试试吧,对我有用!确保您已AllowOverride All
在 httpd.conf 中设置
RewriteEngine On
RewriteCond %{REQUEST_URI} index\.php
RewriteRule ^(.*)index\.php$ // [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]
回答by Zeiss
RewriteRule ^(.*)index\.(html|php)$ http://%{HTTP_HOST}/ [R=301,L]