我想从
重写一些网址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?$
但我需要为每个页面写一遍...... 有没有办法自动完成所有页面?
感谢
答案 0 :(得分: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重写规则)。