我想知道如何从网址中删除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/