如何从 URL 中删除 index.php
How to remove index.php from URLs
我想知道如何从 URL 中删除 index.php,我网站上的每个 link 都包含 index.php,例如例如.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?/ [L]
删除了 index.php 但任何新文章都不会在主页中显示图片(index.php)
然后我尝试使用
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) / [R=301,NE,L]
同样的事情发生了。
请指教
请查看以下 Drupal 8 文档:https://www.drupal.org/docs/8/configuring-clean-urls/enable-clean-urls
这应该可以帮助您启用干净的 URLs。
此外:您可能需要检查以下问题并针对您的问题发表评论:Enable Clean URLs
扩展:尝试检查图像的 src URL(如果它们包含 index.php,否则可能是权限配置错误)
编辑:在您的 .htaccess 中尝试此代码
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
On a side note: You might want to consider switching to PHP7 since active support for PHP5.6 will end soon. (Source)
这是我添加到我的 apache 配置中的内容。
# Sometimes (multiple instances of) index.php/ get(s) inserted in URLs
# Remove them
RewriteCond %{REQUEST_URI} ^/(index.php/)+(.*)
RewriteRule ^.*$ /%2 [R=301,END]
显然,某些 "simple XML sitemap" 版本引入了这些 index.php 部分并将它们提交给搜索引擎,现在我得到了那些不干净的 url。
配置 drupal 不使用它们是一回事,但告诉客户那些 URL 不再有效是另一回事。这就是上面的派上用场的地方。它只是删除 URL.
中的所有 index.php/ 部分
注意:这必须放在所有其他重写规则之前!
我想知道如何从 URL 中删除 index.php,我网站上的每个 link 都包含 index.php,例如例如.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?/ [L]
删除了 index.php 但任何新文章都不会在主页中显示图片(index.php)
然后我尝试使用
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) / [R=301,NE,L]
同样的事情发生了。
请指教
请查看以下 Drupal 8 文档:https://www.drupal.org/docs/8/configuring-clean-urls/enable-clean-urls
这应该可以帮助您启用干净的 URLs。
此外:您可能需要检查以下问题并针对您的问题发表评论:Enable Clean URLs
扩展:尝试检查图像的 src URL(如果它们包含 index.php,否则可能是权限配置错误)
编辑:在您的 .htaccess 中尝试此代码
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
On a side note: You might want to consider switching to PHP7 since active support for PHP5.6 will end soon. (Source)
这是我添加到我的 apache 配置中的内容。
# Sometimes (multiple instances of) index.php/ get(s) inserted in URLs
# Remove them
RewriteCond %{REQUEST_URI} ^/(index.php/)+(.*)
RewriteRule ^.*$ /%2 [R=301,END]
显然,某些 "simple XML sitemap" 版本引入了这些 index.php 部分并将它们提交给搜索引擎,现在我得到了那些不干净的 url。
配置 drupal 不使用它们是一回事,但告诉客户那些 URL 不再有效是另一回事。这就是上面的派上用场的地方。它只是删除 URL.
中的所有 index.php/ 部分注意:这必须放在所有其他重写规则之前!