我已使用以下代码将我的网页网址从localhost/products.php
更改为localhost/products
。
RewriteCond %{THE_REQUEST} /products\.php[\s/?] [NC]
RewriteRule ^ /products [R=301,L]
RewriteRule ^products/?$ products.php [L,NC]
但是当我导航到下一页时,地址栏会显示如下内容:
localhost/products?page=2
我希望显示为localhost/products/page2
试过这个RewriteRule ^products/page/([0-9]+)/?$ products.php?page=$1 [L]
,但这不起作用。
我重写页面网址的完整代码是:
RewriteCond %{THE_REQUEST} /products\.php[\s/?] [NC]
RewriteRule ^ /products [R=301,L]
RewriteRule ^products/?$ products.php [L,NC]
RewriteRule ^products/page/([0-9]+)/?$ products.php?page=$1 [L]
在这里如何更改下一页的网址?我的意思是从localhost/products?page=2
到localhost/products/page2
等等。
答案 0 :(得分:0)
您可以使用以下规则:
RewriteCond %{THE_REQUEST} /products/?(?:\.php)?\?page=([^\s&]+) [NC]
RewriteRule ^ /products/%1? [R=301,L]
RewriteRule ^products/([0-9]+)/?$ /products.php?page=$1 [L,NC]
这将转换网址
到