htaccess和两个post参数 [英] htaccess and two post parameters
问题描述
我为我的网站开发了一个小型的自定义MVC框架.它是index.php检查$ _POST ['page']& $ _POST ['subpage'],并包含指定参数的相关php文件.
I developed a small custom MVC framework for my website. it's index.php check $_POST['page'] & $_POST['subpage'] and includes related php file for specified parameter.
例如: index.php?page = foods (其中包括view/foods.php)
例如: index.php?page = foods& subpage = pizza (其中包括view/foods/pizza.php)
现在,我想使用.htaccess清理我的URL.我尝试了几种方法来传递第二个参数.但是我失败了.效果很好...
Now I want to clean my URLS using .htaccess. I tried few methods to pass second parameter. But I failed. This works fine...
RewriteEngine on
RewriteRule ^([^/\.]+)?$ index.php?page=$1 [L]
但是当我尝试传递第二个参数时,它不能正常工作.这一更改css/js/iamges路径.
But when i tried to pass second parameter its not working fine. This one change css/js/iamges path.
RewriteEngine on
RewriteRule ^([^/\.]+)?$ index.php?page=$1
RewriteRule ^([^/\.]+)/([^/\.]+)?$ index.php?page=$1&sub=$2
推荐答案
如果使用QSA(查询字符串暂停)标志,则只需将整个请求字符串传递给索引文件-
If you use the QSA (Query String Apend) flag, you can simply pass the entire request string to an index file -
QSA -将来自原始请求URL的任何查询字符串附加到在重写目标中创建的任何查询字符串
QSA - Appends any query string from the original request URL to any query string created in the rewrite target
所以您的规则看起来与此类似-
So your rule would look similar to this -
RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
在索引文件中,您可以.explode()
以斜杠-
In your index file you can .explode()
by slashes -
$splitArr = explode('/',$_GET['uri']);
和/或使用内置的parse_url()
函数- http: //www.php.net/manual/zh-CN/function.parse-url.php
And/or use the built in parse_url()
function - http://www.php.net/manual/en/function.parse-url.php
parse_url
—解析URL并返回其组成部分
parse_url
— Parse a URL and return its components
这篇关于htaccess和两个post参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!