如何允许由.htaccess中的URL三个可选参数? [英] How to allow three optional parameters in the URL by .htaccess?

查看:109
本文介绍了如何允许由.htaccess中的URL三个可选参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 http://example.com 并检查是否某些URL存在PHP路由类。
我想打一个新的途径,那就是:

I have http://example.com and a PHP routing class that checks if some URL exists.
I want to make a new route, which is:

http://example.com/foo/bar/123

但只要我打开它,Apache的重定向我到一个错误页面。所以我使用的.htaccess。在code是:

but as long as I open it, the Apache redirects me to an error page. So I'm using a .htaccess. The code is:


RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)  /index.php [L]

和它的工作原理,只要我使用 http://example.com/foo ,但一旦我添加一些其他的参数,它重定向我的错误。

and it works, as long as I use http://example.com/foo, but once I add some other parameters, it redirects me to an error.

我猜测,改写code是错误的。是不是错了?
如果是的话,你能建议我好吗?
如果没有,问题出在哪里可以找到?

I'm guessing that the rewrite code is wrong. Is it wrong?
If yes, could you suggest me the good one?
If no, where the problem could be located?

推荐答案

您可以处理URI与PHP的:

You can handle the URI with php:

的.htaccess:

.htaccess:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

PHP的:

php:

if (isset($_SERVER['REQUEST_URI']))
{
    $params = explode("/", ltrim($_SERVER['REQUEST_URI'], "/"));
    print_r($params);
}

example.com/just/these/params

输出:

Array
(
    [0] => just
    [1] => these
    [2] => params
)

这篇关于如何允许由.htaccess中的URL三个可选参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆