【问题标题】:removing index.php and .php extension from all pages using .htaccess使用 .htaccess 从所有页面中删除 index.php 和 .php 扩展名
【发布时间】:2021-12-08 03:37:16
【问题描述】:

我在 .htaccess 中添加了这段代码,用于从 url 中删除 .php 扩展名。我还编写了一个代码,用于使博客 url 像 https://url.com/posttitle 一样对 seo 友好

<IfModule mod_rewrite.c>
    #removing extension from url
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    #blog
    #if the file with the specified name in the browser doesn’t exist, or the directory in the browser doesn’t exist then procede to the rewrite rule below
    RewriteCond %{REQUEST_FILENAME} !-d [NC]
    RewriteCond %{REQUEST_FILENAME} !-f [NC]
    RewriteRule ^(.*)$ blog_detail.php?id=$1 [QSA,L]   
</IfModule>

我已经添加了主页之类的链接。

首页

在这种情况下如何从 url 中删除索引?

【问题讨论】:

  • 大概您实际上并没有链接到index.php,这仅适用于链接到旧 URL 的 SEO 和第三方?

标签: .htaccess url indexing


【解决方案1】:

导航到根目录 (index.html/.php) 时,您可以在 href 属性中简单地使用 "/"

【讨论】:

    猜你喜欢
    • 2018-12-04
    • 1970-01-01
    • 1970-01-01
    • 2013-01-03
    • 2011-03-02
    • 2014-03-04
    • 2019-07-08
    • 2011-04-30
    相关资源
    最近更新 更多