apache url为TheGamesDB.net重写

时间:2011-10-06 22:37:14

标签: apache url-rewriting

据我所知,我遇到了一些差距。

我正在尝试在我开发的网站上启用友好(或友好)网址:http://thegamesdb.net

要更深入地了解我们当前的网址格式,请查看我刚才提供的网站链接。但是对于快速概述,这里有几个示例网址:

http://thegamesdb.net/?tab=game&id=90&lid=1

http://thegamesdb.net/?tab=adminstats&statstype=topratedgames

http://thegamesdb.net/index.php?string=Sonic+the+Hedgehog&searchseriesid=&tab=listseries&function=Search

是否有人知道适当的代码来配置htaccess文件以更友好的方式重写这些?我已经自己动手了,但它一直在吹我的思绪而不工作......安装了apache mod_rewrite。

老实说,我很高兴能够解决隐藏的“index.php”和要重写的“tab”参数,至少我会给你一些代码来启动用。

提前致谢,

亚历克斯:)

1 个答案:

答案 0 :(得分:8)

以下是您可以使用/做的内容的骨架:

RewriteEngine On
RewriteBase /

# http://thegamesdb.net/?tab=game&id=90&lid=1 => http://thegamesdb.net/tab/games/90/1
RewriteRule ^tab/games/([0-9]+)/([0-9]+)(/?)$ index.php?tab=game&id=$1&lid=$2 [NC,QSA,L]

# http://thegamesdb.net/?tab=adminstats&statstype=topratedgames => http://thegamesdb.net/admin/stats/top-rated-games
RewriteRule ^admin/stats/([a-z0-9\-]+)(/?)$ index.php?tab=adminstats&statstype=$1 [NC,QSA,L]

# http://thegamesdb.net/index.php?string=Sonic+the+Hedgehog&searchseriesid=&tab=listseries&function=Search => http://thegamesdb.net/list-series/search/Sonic+the+Hedgehog/
RewriteRule ^([a-z0-9\-\.\+\ ]+)/search/([a-z0-9\-\.\ \+]+)(/?)$ index.php?tab=$1&string=$2&searchseriesid=&function=search [NC,QSA,L]

# http://thegamesdb.net/index.php?string=Sonic+the+Hedgehog&searchseriesid=&tab=listseries&function=Search => http://thegamesdb.net/list-series/search/Sonic+the+Hedgehog/12
RewriteRule ^([a-z0-9\-\.\+\ ]+)/search/([a-z0-9\-\.\ \+]+)/([0-9]+)(/?)$ index.php?tab=$1&string=$2&searchseriesid=$3&function=search [NC,QSA,L]