Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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 修改重写问题_Php_Apache_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php 修改重写问题

Php 修改重写问题,php,apache,mod-rewrite,url-rewriting,Php,Apache,Mod Rewrite,Url Rewriting,在apache.htaccess文件中,我写到 重写规则^animals$index.php?type=animals 它重定向到 当url键入为时,就会出现错误, 找不到文件 什么是正确的语法来执行这两项操作以及重定向到应该可以: RewriteRule ^animals/?$ index.php?type=animals 尝试RewriteRule^animates/?$index.php?type=animates您应该使用L标志来标记规则的结束,并使用QSA来保留新的查询参数,如下所示

在apache.htaccess文件中,我写到

重写规则^animals$index.php?type=animals

它重定向到
当url键入为时,就会出现错误, 找不到文件

什么是正确的语法来执行这两项操作以及重定向到

应该可以:

RewriteRule ^animals/?$ index.php?type=animals

尝试
RewriteRule^animates/?$index.php?type=animates

您应该使用
L
标志来标记规则的结束,并使用
QSA
来保留新的查询参数,如下所示:

RewriteRule ^animals/?$ index.php?type=animals [L,QSA,NC]

NC用于无案例比较。

这是通过设置此规则完成的,如果指定了基本路径,则所有链接都将获得基本路径

RewriteBase / 

页面在两个
http://localhost/animals/
http://localhost/animals
但是当我使用
http://localhost/animals/
然后不加载css、js文件。但是使用
http://localhost/animals
@BhaveshGangani您应该使用css和js文件的所有引用(以及其他html页面的链接)对html进行编码,这些引用与您的项目路径绝对相关。因此,如果您的网站位于所有位置,则指向文件的链接必须类似于
/css/style.css
,而不仅仅是
css/style.css
。如果您的页面位于,则所有链接必须像
/yoursite/css/style.css
他就是规则
重写规则^animals/?$index.php?page=animals
,目录位于
http://localhost/zoo/
请求的页面将是
http://localhost/zoo/animals
http://localhost/zoo/animals/
两者都有当我使用
http://localhost/zoo/animals
没有问题,所有文件都会加载,当我加载时
http://localhost/zoo/animals/
页面已加载,但未加载js、css文件,这是JSFIDLE代码,当然.htaccess文件位于
localhost/zoo/.htaccess