使用 .htaccess 从 URL 中删除“index.php" [英] Remove 'index.php' from URL with .htaccess

查看:31
本文介绍了使用 .htaccess 从 URL 中删除“index.php"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试来自该站点的各种解决方案,但似乎都没有奏效.我目前正在使用 hostgator 托管.这是我当前的 .htaccess 文件:

I've been trying all sorts of solutions from this site and none seem to work. I'm currently hosting with hostgator. This is my current .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
<IfModule mod_suphp.c>
    suPHP_ConfigPath /home/user/php.ini
    <Files php.ini>
        order allow,deny
        deny from all

    </Files>
</IfModule>

这是在我网站的根文件夹中.我也试过在 index.php 之后添加一个 ? ,但没有成功.有谁知道为什么这不起作用?

This is in the root folder of my site. I have also tried adding a ? after index.php and no luck. Does anyone know why this isn't working?

推荐答案

这是您可以在 .htaccess(在 DOCUMENT_ROOT 下)中用于从 URI 中删除 index.php 的代码:

This is the code you can use in your .htaccess (under DOCUMENT_ROOT) to remove index.php from URI:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

这篇关于使用 .htaccess 从 URL 中删除“index.php"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆