Htaccess RewriteRule不工作,而它应该工作



经过一点谷歌搜索,我认为我有一个.htaccess文件应该可以工作。这个想法很简单,如果domain.com/之后的东西存在,它应该显示它,否则它会重写到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。

谢谢,Robin

如果放在根目录上,请在htaccess中定义重写基

RewriteBase /

更改此行

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

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

不要在RewriteRule 上写第一个斜杠

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

它应该这样工作

编辑:试试这个

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

最新更新