Php 修改重写问题
在apache.htaccess文件中,我写到 重写规则^animals$index.php?type=animals 它重定向到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来保留新的查询参数,如下所示
当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