[英]htaccess example.com/page.php?cat=berlin&page=2 to example.com/berlin/2
I've searched all over the web but have not been able to find answers, so i hope you can help me. 我在网上搜索了所有内容,但找不到答案,所以希望您能为我提供帮助。
I try to rewrite both the page and the category in my Htaccess as follows: example.com/page.php?cat=berlin&page=2 to example.com/berlin/2. 我尝试将Htaccess中的页面和类别都重写为:example.com/page.php?cat=berlin&page=2到example.com/berlin/2。 Category can be different like Stockholm, Oslo, Copenhagen ... 类别可以不同,例如斯德哥尔摩,奥斯陆,哥本哈根...
Is there anybody inside that can show me how to do it? 里面有人可以告诉我该怎么做吗? Or refer to a place where they show it correctly. 或参考他们正确显示它的地方。 I have try to use %1 but it did not work. 我尝试使用%1,但没有用。
RewriteRule ^(.*)$ /book.php?url=$1 [L]
You would need to use back-references and multiple capture groups to accomplish this. 您将需要使用反向引用和多个捕获组来完成此操作。 So something like: 所以像这样:
RewriteRule ^/page.php\?cat=([a-z]+)&page=([0-9]+)$ /$1/$2 [L]
This is making several assumptions, including that cat
is always alpha characters and page
is always numeric. 这有几个假设,包括cat
始终为字母字符, page
始终为数字。 Also see the apache documentation here , specifically the section on Regex Back-Reference Availability. 另请参阅此处的apache文档,特别是Regex反向引用可用性部分。
Also, %1
would match a capture group in a preceding RewriteCond
not the current RewriteRule
which uses the $1
notation. 另外, %1
将匹配先前的RewriteCond
中的捕获组,而不是使用$1
表示法的当前RewriteRule
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.