使用htaccess php的自定义路由

塔拉图拉

与标题相同,我想看起来像这样:

.htaccess文件:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule / index.php?r=site&action=index
RewriteRule ^user/[0-9]+$ index.php?r=user&action=profile&user_id=$1

但它不起作用,例如:

网址:“ http://mysite.domain/

$route = filter_input(INPUT_GET, 'r'); // $route = null;

有人可以帮助我吗?

林俊

/请求时没有斜杠处理htaccess文件中的规则时,将从URI中删除前导斜杠。尝试:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(?:index\.php)$ index.php?r=site&action=index [L,QSA]
RewriteRule ^user/[0-9]+$ index.php?r=user&action=profile&user_id=$1 [L,QSA]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章