linux - .htaccess 将 index.php 重定向到/

标签 linux apache .htaccess redirect mod-fcgid

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

最佳答案

尝试一下,它对我有用!确保在 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]

关于linux - .htaccess 将 index.php 重定向到/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14733988/

相关文章:

linux - pthread mutexattr 进程共享内存泄漏

linux - 使用linux系统调用在基本TCP服务器中获取http header

linux - .htaccess 将子域+文件夹重写为uri

php - 在 PHP 中将 JSON 对象插入 MySQL 表时出现问题

php - htaccess : disallow all pdf files but allow from php script (file download script)

linux - 程序从终端运行良好,但不能从 shell 脚本运行

linux - cron 中脚本的相对路径的语法是什么?

php - 如何在 Linux 共享主机上启用 php_mbstring 和 php_exif 扩展

python - 如何将 flask 应用程序部署到 ubuntu

.htaccess - htaccess 重定向避免特定域