【问题标题】:How to redirect from index.php to index [duplicate]如何从 index.php 重定向到索引 [重复]
【发布时间】:2014-05-29 09:28:58
【问题描述】:

所以我对 Apache 的 mod_rewrite 有点挣扎,但最终设法配置(是)并理解它(也许?)。

当用户转到/index 时,他们会看到/index.php 页面,并且浏览器的网址是http://example.com/index

用户也可以访问/index.php,浏览器的url为http://example.com/index.php

RewriteEngine On 
RewriteBase /
RewriteRule ^index$ /index.php
RewriteRule ^$ /index.php

所以我的问题是,如何仅使用服务器的配置将用户从 /index.php 重定向到 /index

【问题讨论】:

  • 请告诉我们你的重写规则!

标签: php apache .htaccess mod-rewrite


【解决方案1】:

我不太清楚你的意思。

在 .htaccess 中删除扩展名 .php 你可以使用这个:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

我确实相信这一点:

RedirectMatch 301 (.*)\.php$ http://www.example.com$1

应该可以删除 .php

也许可以试试?

【讨论】:

  • 我收到了Internal server error
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-03
相关资源
最近更新 更多