简体   繁体   English

htaccess example.com/page.php?cat=berlin&page=2到example.com/berlin/2

[英]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.

相关问题 如何使用 .htaccess 重写 example.com/catelogue.php?page=3&cat1=fruit&cat2=apple - How to rewrite example.com/catelogue.php?page=3&cat1=fruit&cat2=apple with .htaccess .htaccess用于分页以重定向example.com/page/page_id - .htaccess for pagination to redirect example.com/page/page_id 是否可以将 example.com/index.php?page=abc 重定向到 example.com/abc? - Is it possible to redirect the example.com/index.php?page=abc to example.com/abc? 检测URL标记example.com/page.php#anycontent - Detect URL tags example.com/page.php#anycontent “ example.com/index.php/page/about/”是好的做法吗? - Is “example.com/index.php/page/about/” good practice? htaccess将example.com/user.php?id=username重写为example.com/username - htaccess rewrite example.com/user.php?id=username to example.com/username 使用,htaccess将example.com?id=12重定向到example.com/index.php?id=12 - using ,htaccess redirect example.com?id=12 to example.com/index.php?id=12 Avoid multiple page redirects http://example.com > https://example.com -> https://www.example.com - Avoid multiple page redirects http://example.com > https://example.com -> https://www.example.com 如何使用.htaccess将http://example.com/test.php设置为http://example.com/index.php?do=test? - How to make http://example.com/test.php to http://example.com/index.php?do=test using .htaccess? 只允许查看从 example.com/login 重定向的页面 - Only allow to view a page that is redirected from example.com/login
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM