mod_rewrite的$ _GET [英] mod_rewrite $_GET

查看:148
本文介绍了mod_rewrite的$ _GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 FrontController 预计两个 $ _ GET PARAMS:

I have a FrontController expecting two $_GET params:

controller
action

该网站一个典型的调用看起来是这样的:

A typical call to the site would look like this:

http://foo.bar/index.php?controller=start&行动=注册

我想要做的就是让用户通过以下网址访问这个网站:

What I want to do is to allow the user to visit this site by the following url:

http://foo.bar/start/register

我已经试过:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.+)/(.+)$ index.php?controller=$1&action=$2 [L,QSA]
</IfModule>

因为这给了我404错误它似乎并没有工作。

Since this gives me 404 Errors it doesn't seem to work.

的mod_rewrite 本身在服务器上启用。

mod_rewrite itself is enabled on the server.

推荐答案

的.htaccess 您发布的作品对我来说:

The .htaccess you posted works for me:

// GET /cont1/action1

print_r($_GET);

/* output
Array
(
    [controller] => cont1
    [action] => action1
)
*/

您可能会想尝试的index.php 的绝对路径,而不是相对的。

You might want to try an absolute path to index.php rather than a relative one.

无论如何,该正则表达式将导致:

Regardless, that regex will result in:

// GET /cont1/action1/arg1

print_r($_GET);

/* output
Array
(
    [controller] => cont1/action1
    [action] => arg1
)
*/

您会更好做的:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>

和让你的的index.php 分裂的 $ _ GET ['链接'] 成控制器,动作, ARGS,等等...

And having your index.php split up the $_GET['url'] into controller, action, args, etc...

这篇关于mod_rewrite的$ _GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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