.HTACCESS重写到index.php?p = home

时间:2014-05-20 09:03:44

标签: html .htaccess

所以我一直在使用脚本一段时间,但在丢失文件并需要重新开始工作后,我遇到了一个问题。

当用户转到http://example.com/index.php时,他们会将其重定向到http://example.com/index.php?p=home

不确定我是否有错误的.HTACCESS,但这就是我所拥有的:

RewriteEngine on

RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^/?$ index.php?p=home [L]

[我还希望其他网页能够正常工作,例如index.php?p = blog] 此刻,在主页上获取内容的唯一方法是单击指向index.php的链接?p = home。

希望有人可以解决这个问题。感谢

2 个答案:

答案 0 :(得分:0)

您提到的代码不会这样做。要从一个特定页面到另一个页面执行简单的301重定向,只需将其放在VirtualHost文件中( .htaccess文件)

Redirect 301 example.com/index.php example.com/index.php?p=home

您可以通过here on the Apache site了解更多相关内容。

答案 1 :(得分:0)

您的规则只会重写example.comexample.com/

您还需要重写example.com/index.php

RewriteEngine on

RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteRule ^/?(index.php)?$ index.php?p=home [L]

有什么好处吗?