regex - 使用 .htaccess 从 URL 中删除 'index.php'

标签 regex apache .htaccess mod-rewrite redirect

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

<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没有运气。有谁知道为什么这不起作用?

最佳答案

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

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]

关于regex - 使用 .htaccess 从 URL 中删除 'index.php',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9608366/

相关文章:

regex - 如何在 REGEX 表达式中间包含一个子字符串(除了精确的子字符串)?

HTTP 请求 header 的 Python 正则表达式

php - 地址栏不变 - PHP

c# - 极其奇怪的 ClickOnce Web 部署行为(缓存)

.htaccess - 限制通过其父框架/域以外的任何内容访问 iframed 域

javascript - 用于提取 HTML 标签子元素的正则表达式?

正则表达式用星号模式替换电话号码

Apache 监听配置

.htaccess URL 小写

WordPress 尾部斜线