Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Htaccess重写规则在应该运行时不工作_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php Htaccess重写规则在应该运行时不工作

Php Htaccess重写规则在应该运行时不工作,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,在谷歌搜索了一下之后,我想我有了一个.htaccess文件,应该可以使用了。 这个想法相当简单,如果domain.com/之后的东西存在,它应该显示它,否则它会重写index.php?p= RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.* - [L] RewriteRule ^/(.*)/ index.php?p=$1 现在,当我

在谷歌搜索了一下之后,我想我有了一个.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_重写

谢谢,
Robin

如果位于根目录中,请在htaccess中定义重写库

RewriteBase /

不要在规则上写第一个斜杠

RewriteRule ^(.*)/ index.php?p=$1
应该是这样的

编辑:试试这个

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

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


您的文件放在哪里?它是在根目录还是任何子目录中?添加了这一点,但它没有更改任何内容,仍然给出错误消息,即请求的目录不存在。然后我把它改为RewriteRule^(.*)/index.php?p=$1,现在它说/public_html/index.php不存在。。虽然它确实存在,但是.404找不到请求的目录将this/index.php/$1更改为this/index.php?p=$1它现在尝试加载index.php,但它给出了一个找不到index.php的错误。。而它确实存在于系统正在查找它的目录中。可能是我目前正在使用的temp。url server.ext/~user/而不是完整域?
RewriteRule ^/?(.*)/? index.php?p=$1