【问题标题】:Remove index.php from website home url [duplicate]从网站主页 url 中删除 index.php [重复]
【发布时间】:2018-02-09 01:10:57
【问题描述】:

我的网站主页中有 index.php,并尝试将其删除以用于某些 SEO 目的,如下所示,但我无法通过使用我的 htacess 中的脚本来做到这一点

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]

</IfModule>

我怎样才能删除 index.php

【问题讨论】:

  • 试试 robots.txt 文件,作为 .htaccess 的替代 SEO,你可以使用 no index, no follow。
  • 有什么方法可以通过 HTACCESS 做到这一点?
  • htaccess 将使您的网站无需放置 index.php 即可运行,但不会阻止机器人访问它。如果您愿意,可以尝试添加重定向,可能是站点地图或robot.txt?但是您的 htaccess 似乎还不错...
  • 同时,您可以从所有 URI 中删除 index.php,因为 /?var=value 与 /index.php/?var=value 相同!用&lt;a href="/"&gt;...&lt;/a&gt;就够了!
  • SO 有数百个问题已经回答了这个问题

标签: php .htaccess url


【解决方案1】:

这是从 URL 中隐藏 index.php 的基本规则。把这个放进去 你的根 .htaccess 文件。 mod_rewrite 必须使用 PHP 和 这适用于高于 5.2.6 的 PHP 版本。

试试这个

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

【讨论】:

  • Wordpress 使用这个。而且它的工作时间很长。
  • 我正在使用自定义 php 网站,它仍然可以工作吗?
  • 我不明白为什么不 - 这对我来说很好
猜你喜欢
  • 2015-12-14
  • 2010-10-28
  • 1970-01-01
  • 2015-09-06
  • 2020-08-12
  • 1970-01-01
  • 2012-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多