0

我想重写一些网址

www.example.ro/women_shoes.php 到 www.example.ro/women-shoes/ 并且分页看起来像 www.example.ro/women_shoes.php?page=1 到 www.example.ro/women_shoes/pagina-2 /

www.example.ro/men_shoes.php 到 www.example.ro/men-shoes/ 与第一个一样的分页

www.example.ro/sandale_barbati.php 到 www.example.ro/sandale-barbati/ 等等..

对于我尝试的最后一个示例

RewriteRule ^sandale-barbati/pagina-([0-9]+)/ /sandale-barbati.php?page=$1 [L]
RewriteRule ^sandale-barbati/?$ /sandale_barbati.php?$

但我需要为每一页都写...有没有办法自动为所有页面做到这一点?

谢谢

4

1 回答 1

1

如果您始终对所有页面使用相同的命名,这将起作用:

RewriteRule ^([a-zA-Z]+)([-_]){1}([a-zA-Z]+)/pagina-([0-9]+)/$ $1_$3.php?page=$4
RewriteRule ^([a-zA-Z]+)([-_]){1}([a-zA-Z]+)/$ $1_$3.php
RewriteRule ^([a-zA-Z_]+)/pagina-([0-9]+)/$ /$1.php?page=$2
RewriteRule ^([a-zA-Z_]+)/$ /$1.php

You can surf to /women_shoes/ and it will be the /women_shoes.php page.
You can surf to /women-shoes/ and it will be the /women_shoes.php page.
You can surf to the /shoes/ and it will be the /shoes.php page.

我希望这已经满足了您的所有要求,并且对您有足够的帮助。为了将来参考,网站http://www.regular-expressions.info/在处理 RegEx(如 .htaccess 重写规则)时非常方便。

于 2012-08-11T14:26:12.987 回答