【发布时间】:2014-01-05 19:12:25
【问题描述】:
今天我尝试创建将? 和= 替换为/ 的.htaccess 文件,
test.php 代码:
<?php
echo $_GET['myparam'];
?>
.ht 访问:
我使用了这个写规则:
RewriteEngine On
RewriteBase /
RewriteRule ^test/myparam/([0-9]+)/?$ test.php?myparam=$1 [NC,QSA,L]
好的,我导航到 www.web.com/test.php?myparam=123
没有重定向到 www.web.com/test/myparam/123
所以导航到:www.web.com/test/myparam/123(手动)并且php脚本工作,
我将 myparam 值更改为 abc 而不是 123:www.web.com/test/myparam/abc
然后它重定向到 404 not found 页面...(服务器不知道 abc 不是目录 when integer works when string 404)
!所以我想做什么:!
www.web.com/test .php? inttParam = 1 & strrParam = stringhere & p = 1
至
www.web.com/test/inttParam/1/strrParam/stringhere/p/1
当我使用$_GET['p'] 时,它会起作用。
【问题讨论】:
-
当然,将 123 更改为 abc 是行不通的——重写仅匹配数字。如果没有将 URI 更改为“真实”的东西(/test.php 等),它将抱怨找不到 /test/myparam/abc。
-
你在这方面倒退了。 incoming URI 是
/test/myparam/123(SEO),.htaccess 将其转换为/test.php?myparam=123(动态)。如果您输入动态表单,它应该被原封不动地传递,因为它已经在所需的表单中。如果您输入 SEO 表单,它应该以动态形式传递给服务器/PHP。顺便说一句,应该可以为多个术语通用地执行此操作/$1.php?$2=$3&$4=$5&...
标签: php regex apache .htaccess mod-rewrite