Htaccess RewriteRule不应该工作

时间:2014-01-03 10:47:39

标签: php apache .htaccess mod-rewrite

经过一段谷歌搜索后,我想我有一个应该有效的.htaccess文件。 这个想法相当简单,如果域名存在后它应该显示它,否则它会重写index.php?p =。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
RewriteRule ^/(.*)/ index.php?p=$1

现在当我访问domain.com/hello时,我收到一个错误,即“hello”目录不存在。 在请求期间正在使用htaccess文件,因为当我在htaccess代码中放入一些不起作用的东西时,它会出错。

有人能告诉我问题可能是什么吗?

我检查了apache配置并启用了mod_rewrite。

感谢, 罗宾

3 个答案:

答案 0 :(得分:1)

如果htaccess位于根目录

,请在htaccess中定义重写基数
RewriteBase /

答案 1 :(得分:0)

不要在RewriteRule上写第一个斜杠

RewriteRule ^(.*)/ index.php?p=$1

它应该以这种方式工作

编辑:试试这个

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

答案 2 :(得分:0)

更改此行

RewriteRule ^/(.*)/ index.php?p=$1

RewriteRule ^/?(.*)/? index.php?p=$1