【问题标题】:href="blaah" instead of href="blaah.php" and href=".." instead of href="index.php"href="blaah" 而不是 href="blaah.php" 和 href=".." 而不是 href="index.php"
【发布时间】:2014-11-09 00:41:30
【问题描述】:

我看到href="blaah"a 标记的href 属性使用href="blaah.php" 而不是href="blaah.php"。我还看到href=".." 代替了href="index.php"

我已经在 NGINX 服务器上对此进行了测试,但是,当我托管时,我最终可能会通过 Apache 托管。那么,Apache 是否支持href="blaah"

【问题讨论】:

  • 您指的是一种称为 URL 重写的技术:stackoverflow.com/questions/2433545/…
  • 而且大多数时候,可以(并且应该)使用诸如http://example.com/news/ 之类的URL 来代替http://example.com/news/index.php

标签: php html apache nginx hyperlink


【解决方案1】:

您可以为此使用 RewriteEngine,只需将此代码添加到您的 .htaccess。

RewriteEngine On
RewriteBase /

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

此代码将 .php 添加到每个没有扩展名的文件中。

【讨论】:

  • href=".."代替href="index.php"怎么样
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-18
  • 2017-06-04
  • 1970-01-01
  • 2015-12-21
  • 2018-02-08
  • 1970-01-01
  • 2014-02-13
相关资源
最近更新 更多