url rewriting : How to rewrite 2 urls with same number of parameters?

一曲冷凌霜 提交于 2020-01-25 02:46:05

问题


I've created some url rewriting rules.

It works fine.

But i have 2 pages with urls like that :

actualites.php?id=xxx& alias=xxx

--> Result : id-alias.php (ex : 1-article_name.php)

equipe.php?id=xxx& alias=xxx

--> Result : id-alias.php ((ex : 1-article_name.php)

These 2 pages are different, not the same design, etc.

I would like to rewrite these 2 different pages. My question is how to have two different rules for these 2 urls.

Since they have 2 parameters, i have only one rule applied (the first one)

#become : 1-alias.php
RewriteRule  ^([0-9]*)-(.*)\.php$ actualites.php?cat=$1&alias=$2 [L]

#become : 1-alias.php
RewriteRule  ^([0-9]*)-(.*)\.php$ equipe.php?id_equipe=$1&alias=$2 [L]

回答1:


Unless you want to add code in actualites.php that first checks whether the parameter values for "cat" and "alias" are valid, then you can't.

If you want to code that into actualites.php, check if the parameters are valid, and if not, send the params to equipe.php as "id_equipe" and "alias". Otherwise you'll need to add something to the URL to validate which request you're actually mapping to. For example:

http://yourdomain.com/a/1-article.php  -->  /actualites.php?cat=1&alias=article
http://yourdomain.com/e/1-article.php  -->  /equipe.php?id_equipe=1&alias=article

Without that /a/ or /e/, there's no way to tell what to map to. If you don't use something like that, you'll need to do all validation in your php.



来源:https://stackoverflow.com/questions/12963206/url-rewriting-how-to-rewrite-2-urls-with-same-number-of-parameters

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