htaccess rewrite, in an array?

烂漫一生 提交于 2019-12-25 03:59:14

问题


Say I have the following pages:

http://www.site.com/folder/page.php?id=89
http://www.site.com/folder/page.php?id=85
http://www.site.com/folder/page.php?id=camel+hump
http://www.site.com/folder/page.php?id=76
http://www.site.com/folder/page.php?id=71
http://www.site.com/folder/page.php?id=frog
http://www.site.com/folder/page.php?id=62
http://www.site.com/folder/page.php?id=59

and I want to direct the following:

89, 79, 44, camel+hump to the following page:

http://www.site.com/folder/page/$1

EG:

http://www.site.com/folder/camel-hump (Notice the + replaced with a -)

and everything else to the following page:

http://www.site.com/folder/overview

How would I do this?

Basically, I have around 200 pages that need redirecting, and they all have the same URL apart from the get parameter, some of them need redirecting to a /folder/get-parameter page and the rest need redirecting to a /folder/overview page.

I also need + signs to be replaced with - signs, so for example camel+hump becomes camel-hump

How can I do this with a rewrite rule? Something like:

if match (89|79|44|camel+hump|frog) go to /folder/$1 (but replace + with -)

everything else, go to /folder/overview

Thank you


回答1:


Try:

# Filter out the query string values for id that you want to rewrite
RewriteCond %{QUERY_STRING} ^id=(89|79|44|camel\+hump|frog)
RewriteRule ^folder/page.php$ /folder/page/%1?  [L]

# get rid of the +
RewriteRule ^folder/page/(.+)\+(.+)$ /folder/page/$1-$2 [L]


来源:https://stackoverflow.com/questions/8529848/htaccess-rewrite-in-an-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!