htacess和两个后的参数 [英] htacess and two post parameters
问题描述
我开发了一个小型的定制MVC框架为我的网站。它的index.php检查$ _ POST ['页']放; $ _ POST ['子页'],并包括指定的参数相关的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页面=食物 (这包括查看/ foods.php)的
例如:? index.php页面=食品&安培;子页面=比萨饼 (这包括查看/食品/ pizza.php)的
现在我想用的.htaccess清理我的网址。我试过一些方法来传递第二个参数。但我失败了。这工作得很好...
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
请,任何人都可以帮我解决这个问题? :)
Please, anyone can help me to solve this ? :)
推荐答案
如果您使用QSA(查询字符串Apend)标志,你可以简单地传递整个请求字符串到一个索引文件 -
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/en/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
这篇关于htacess和两个后的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!