Apache 如何从URL中删除index.php

Apache 如何从URL中删除index.php,apache,drupal,drupal-8,Apache,Drupal,Drupal 8,我想知道如何从URL中删除index.php,我网站上的每个链接都有index.php,例如example.com/index.php/contact-us 我使用Drupal8,我的服务器是Apache,php版本是5.6,我使用共享主机 在我试图使用的.htaccess文件中 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /

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

我使用Drupal8,我的服务器是Apache,php版本是5.6,我使用共享主机

在我试图使用的.htaccess文件中

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
这删除了index.php,但任何新文章都不会在主页(index.php)中显示图像

然后我试着用

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
同样的事情发生了


请注意

请查看以下Drupal 8文档:

这将帮助您启用干净的URL

此外:您可能需要检查以下问题和注释以了解您的问题:

扩展:尝试检查图像上的src URL(如果它们包含index.php,则可能是权限配置错误)

编辑:在.htaccess中尝试此代码

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^ index.php [L]

一个旁注:您可能需要考虑切换到PHP7,因为对PHP5.6的积极支持很快就会结束。()


这是我添加到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/部分


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

我在那里尝试了几乎所有的东西,仍然面临着同样的问题。我也尝试了它们,仍然是同样的问题,现在当我在RewriteCond%{REQUEST_FILENAME}上使用这个重写引擎时-f RewriteCond%{REQUEST_FILENAME}-重写规则^(.*)$/index.php?/$1[L]它实际上添加了index.php!!!有趣的是,我的本地主机上的同一个网站在没有任何index.php的情况下工作得很好(我使用的是相同的.htaccess文件)再次更新了我的答案:p这是我现在拥有的相同代码,我发誓我在这里会发疯,我不知道我到底做了什么,但是有了你现在发布的代码,这是我的默认代码,现在一切正常。但是当我访问我的/user页面时,它会将我重定向到index.php,然后我需要访问site.com/index.php/userThis最终对我有效。在查看从简单站点地图生成的sitemap.xml时偶然发现了它。现在它又开始工作了!