Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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_Mysql_.htaccess - Fatal编程技术网

Php 使用htaccess将查询重写为路径

Php 使用htaccess将查询重写为路径,php,mysql,.htaccess,Php,Mysql,.htaccess,如何使htaccess重写以下URL结构: http://example.com/detail.php?id=polo&categ=wears 到 http://example.com/wears/polo/ 我已经尝试了下面的代码,但它不适合我 <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^(.+)/(admin|css|fonts|ico|include|js|images|img|products|slide)

如何使
htaccess
重写以下URL结构:

http://example.com/detail.php?id=polo&categ=wears

http://example.com/wears/polo/
我已经尝试了下面的代码,但它不适合我

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.+)/(admin|css|fonts|ico|include|js|images|img|products|slide)/(.*)$ $2/$3 [L]
RewriteRule ^(.*)/(.*)/$ detail.php?id=$1&categ=$2
</IfModule>

重新启动发动机
重写规则^(+)/(管理| css |字体| ico |包括| js |图像| img |产品|幻灯片)/(*)$$2/$3[L]
重写规则^(.*)/(.*)/$detail.php?id=$1&categ=$2

当我在URL中包含尾随斜杠时,您的代码对我有效

工作->
http://example.com/wears/polo/

不工作->
http://example.com/wears/polo

此外,还需要从
*
表达式中排除斜杠字符

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.+)/(admin|css|fonts|ico|include|js|images|img|products|slide)/(.*)$ $2/$3 [L]
RewriteRule ^([^/]*)/([^/]*)/?$ detail.php?id=$1&categ=$2
</IfModule>

重新启动发动机
重写规则^(+)/(管理| css |字体| ico |包括| js |图像| img |产品|幻灯片)/(*)$$2/$3[L]
重写规则^([^/]*)/([^/]*)/?$detail.php?id=$1&categ=$2
试试这个


在每个目录上下文(
.htaccess
文件)中,需要从
重写规则
模式中删除斜杠前缀。(示例中URL的末尾也缺少斜杠。)“您的代码对我有效”-但值是相反的。您需要切换反向引用的顺序
$1
$2
“重写以下URL结构”-请注意,您的代码正试图执行完全相反的操作(这很好)。将URL重写为
/wears/polo/
(这可能会导致404)没有意义。
RewriteEngine on
RewriteRule ^/(\w+)/(\w+)$ detail.php?categ=$1&id=$2 [NC,L]