【问题标题】:.htaccess rewrite url not working.htaccess 重写 url 不起作用
【发布时间】:2014-05-06 02:30:59
【问题描述】:

我正在尝试使用 .htaccess 的重写功能来重写以下 url

http://just-for-testing.com/index.php?type=hello

http://just-for-testing.com/hello

所以我有以下 index.php 文件

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<a href="?type=hello">hello</a>
</body>
</html>

还有 .htaccess 文件

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

但是还是不行,url还是链接到

index.php?type=hello

有人可以帮忙吗?

谢谢

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    你误解了 url 重写的工作原理。

    您的规则允许您打开两个页面页面:

    http://just-for-testing.com/index.php?type=hello
    http://just-for-testing.com/hello
    

    第二个将被重写为第一个,以便您的index.php 页面由服务器处理(查询变量可用)并将结果发送到浏览器。

    为了能够使用它,您不应该在任何地方使用您的原始链接,而只能使用新的网址:

    <a href="/hello">hello</a>
    

    【讨论】:

      猜你喜欢
      • 2015-02-03
      • 2014-08-08
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多