$ _GET URL重写 [英] $_GET URL ReWriting

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

问题描述

大家好.希望我能正确解释.

Hey everyone. Hopefully I can explain this correctly.

我有一些URL,我想通过URL重写来整理一下.例如,我有:

I have some URL's which I would like to tidy up through URL reWriting. For instance, I have:

domain.com/index.php?page=1
domain.com/index.php?page=2
domain.com/index.php?page=3
domain.com/index.php?page=4 etc..

我希望在URL中显示为:

which I would like to be shown in the URL as:

domain.com/page/1
domain.com/page/2
domain.com/page/3
domain.com/page/4 etc..

还有一个简短的问题: -如果重写了URL,是否仍将执行$ _GET查询?

Also a quick question: -Will the $_GET query's still be executed if the URL is rewritten?

非常感谢.我已启用模块,.htaccess已准备就绪.我只需要一些指示.谢谢!

Many thanks ahead of time. I have the modules enabled and the .htaccess is ready to go. i just need some direction. Thanks!

推荐答案

将此添加到您的.htaccess文件中:

Add this to your .htaccess file:

RewriteEngine On
RewriteRule ^page/(\d+)/?$ /index.php?page=$1 [L]

将始终执行GET查询.如果用户键入domain.com/index.php?page=3,则index.php将运行.如果他们输入domain.com/page/3,则mod_rewrite会将其转换为domain.com/index.php?page=3,然后再将其传递给PHP.无论哪种方式,都运行index.php.

The GET queries will always be executed. If the user types in domain.com/index.php?page=3, then index.php will run. If they type in domain.com/page/3, then mod_rewrite will convert it to domain.com/index.php?page=3 before passing it to PHP. Either way, index.php is run.

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

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