apache - 如何从 URL 中删除 index.php

标签 apache drupal drupal-8

我想知道如何从网址中删除index.php,我网站上的每个链接都有index.php,例如example.com/index.php/contact-us。

我使用 Drupal 8,我的服务器是 Apache,php 版本是 5.6,并且使用共享主机。

在 .htaccess 文件中我尝试使用

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

这删除了index.php,但任何新文章都不会在主页(index.php)中显示图像

然后我尝试使用

RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

同样的事情发生了。

请指教

最佳答案

这是我添加到我的 apache 配置中的内容。

# Sometimes (multiple instances of) index.php/ get(s) inserted in URLs
# Remove them
RewriteCond %{REQUEST_URI} ^/(index.php/)+(.*)
RewriteRule ^.*$ /%2 [R=301,END]

显然,一些“简单的 XML 站点地图”版本引入了这些 index.php 部分并将它们提交给搜索引擎,现在我得到了那些不干净的 url 的点击。

配置 drupal 不使用它们是一回事,但告诉客户端这些 URL 不再有效是另一回事。这就是上面的派上用场的地方。它只是删除 URL 中的所有 index.php/部分。

注意:这必须放在所有其他重写规则之前!

关于apache - 如何从 URL 中删除 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39562923/

相关文章:

apache - 您的浏览器发送了此服务器无法理解的请求

性能测试 Apache 与 NodeJs

php - 无法在新服务器上执行 Ajax 查询

php - 停止 PHP/Drupal 中的自动 URL 解码

Apache 2 请求的 URL/在此服务器上找不到

sharepoint - Drupal 与 SharePoint 相比如何

php - PDO_ODBC 的字符编码问题

drupal-8 - drupal 8获取节点中的分类术语值

drupal - 如何在 libraries.yml 文件中为 css 文件指定 rel 属性?

composer-php - 无法将 Drupal Composer 要求解析为一组可安装的软件包