$_GET URL ReWriting

2019-03-02 03:05发布

Hey everyone. Hopefully I can explain this correctly.

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..

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..

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

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

1条回答
放我归山
2楼-- · 2019-03-02 03:17

Add this to your .htaccess file:

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

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.

查看更多
登录 后发表回答