Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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文件在wamp服务器中不工作_Php_.htaccess_Wamp_Wampserver - Fatal编程技术网

Php 为什么此htaccess文件在wamp服务器中不工作

Php 为什么此htaccess文件在wamp服务器中不工作,php,.htaccess,wamp,wampserver,Php,.htaccess,Wamp,Wampserver,我有一个htaccess文件,当url的类型为www.mywebsite.com/news时,它会重定向到index.php 但当url的类型为www.mywebsite.com/news/2时,它会显示index.html,但不会应用css 我在wamp服务器上 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILE

我有一个htaccess文件,当url的类型为www.mywebsite.com/news时,它会重定向到index.php 但当url的类型为www.mywebsite.com/news/2时,它会显示index.html,但不会应用css 我在wamp服务器上

<IfModule mod_rewrite.c>
   RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.php [L]
</IfModule>

重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^index.php[L]

这是因为
/news/2
创建了一个虚拟目录。
由于您正在为html链接使用相对路径,因此它不起作用

让我们假设您有一个像这样的css链接

因为您的URI是
/news/2
,它将在
/news/style.css
中搜索,而这不是您想要的

相反,请使用绝对路径。
例如:
(带一个前导斜杠,如果不在根文件夹中,可能还有另一个基数)

另外,在htaccess中加一个
RewriteBase/
(或者在
index.php
前面加一个前导斜杠)也没有什么坏处


嗨,兄弟,当我添加RewriteRule^/index.php[L]时,我正在处理wamp本地服务器ans,它将我重定向到本地服务器主页,我的css就像你应该在你的问题中编写它一样,否则就不完全一样了。你能告诉我你的项目在哪个文件夹里吗?(你使用哪个本地主机url访问它?)css文件夹呢,它也在项目文件夹中吗?我的项目在project\u news中是的css在同一个文件夹localhost/project\u news中确定你可以看到我编辑的答案,现在应该可以正常工作了
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ /index.php [L]
</IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /project_news/

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.php [L]
</IfModule>