简体   繁体   English

.htaccess将index.php重定向到/

[英].htaccess redirect index.php to /

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仍然显示

Try, It works for me! 试试吧,它对我有用! Make sure your have AllowOverride All set in httpd.conf 确保在httpd.conf中设置了AllowOverride All

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]
RewriteRule ^(.*)index\.(html|php)$ http://%{HTTP_HOST}/$1 [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM