多个不同的PHP页面需要是友好的URL - URL重写 [英] Multiple different php pages need to be friendly URL - url rewrite
本文介绍了多个不同的PHP页面需要是友好的URL - URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有PHP的网站有多个不同的PHP页面:
I have php website has multiple different php pages:
Example:
http://www.mywebsite.com/post.php?group_id=10&post_id=1
http://www.mywebsite.com/image.php?group_id=10&img_id=1
http://www.mywebsite.com/poll.php?group_id=10&poll_id=1
http://www.mywebsite.com/group.php?group_id=10
http://www.mywebsite.com/user.php?uid=158
....
我需要这些URL是这样的:
I need these URLs to be like the following:
http://www.mywebsite.com/post/10/1
http://www.mywebsite.com/image/10/1
http://www.mywebsite.com/poll/10/1
http://www.mywebsite.com/group/10
http://www.mywebsite.com/user/158
....
注:并非这些网页只是我有,我有很多的网页这样这些页
Note: Not these pages just I have, I have many pages like this these page.
我的htaccess文件如下:
my htaccess file as the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [NC,L]
</IfModule>
在我的htaccess的问题重定向到一个索引页,我怎样才能让htaccess的重定向到每个页面其PARAMS。
the problem in my htaccess redirect to single index page, how can i make htaccess redirect to each page with its params.
推荐答案
中加入一些独特的路径规则的另一个解决方案,
another one solution by adding some unique paths to the rules,
example:
RewriteRule ^news/([^/]*)\.html$ /posts.php?id=$1 [L]
RewriteRule ^polls/([^/]*)\.html$ /polls.php?id=$1 [L]
result:
domain.com?posts.php?id=421 -> domain.com/news/421.html
domain.com?polls.php?id=17 -> domain.com/polls/17.html
这篇关于多个不同的PHP页面需要是友好的URL - URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文