简体   繁体   English

htaccess分页和多个查询字符串

[英]Htaccess pagination and multiple query strings

I'm trying to setup a redirect in order to showcase a business page, with the listings on that page, paginated. 我正在尝试设置重定向以展示业务页面,并在页面上分页显示该页面上的列表。

This is how I want the URL to look like: 这就是我希望网址看起来像的样子:

https://www.propertypost.lk/company/colomborent/1

Where the last number in the URL, is the page number. URL中的最后一个数字是页码。

I've been able to get this to work: https://www.propertypost.lk/company/colomborent 我已经能够使它工作: https : //www.propertypost.lk/company/colomborent

But I can't seem to figure out how to include the pagination part (which shouldn't be mandatory). 但是我似乎无法弄清楚如何包括分页部分(这不是必须的)。

This is how the URL looks without htaccess: 这是没有htaccess的URL的外观:

https://www.propertypost.lk/agent-business-page.php?url=colomborent&page=1

And here is my htaccess rewrite rule that works: 这是我的htaccess重写规则,该规则有效:

RewriteRule     ^company/([^\s]+[\w])/?$    agent-business-page.php?url=$1

And this is what I tried which does not work...: 这是我尝试的不起作用...:

RewriteRule     ^company/([^\s]+[\w])/([^\s]+[\w])/?$   agent-business-page.php?url=$1&page=$2

Thanks for all the help! 感谢您的所有帮助!

You want \\d instead of \\w to capture the numerical pagination number argument. 您希望\\ d而不是\\ w捕获数字分页数参数。 So something like: 所以像这样:

RewriteEngine on
RewriteRule ^/?company/(\w+)/?$ /agent-business-page.php?url=$1 [END]
RewriteRule ^/?company/(\w+)/(\d+)/?$ /agent-business-page.php?url=$1&page=$2 [END]

In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. 如果您使用上述规则收到内部服务器错误(http状态500),则很可能是您运行了非常旧版本的apache http服务器。 You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. 在这种情况下,您将在http服务器错误日志文件中看到对不支持的[END]标志的明确提示。 You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup. 您可以尝试升级或使用旧的[L]标志,在这种情况下它可能会起作用,尽管这在一定程度上取决于您的设置。

This rule will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). 此规则将在http服务器主机配置或动态配置文件(“ .htaccess”文件)中同样起作用。 Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. 显然,重写模块需要加载到http服务器内部并在http主机中启用。 In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder. 如果使用动态配置文件,则需要注意在主机配置中完全启用了它的解释,并且该解释位于主机的DOCUMENT_ROOT文件夹中。

And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). 还有一个一般性说明:您应该始终喜欢将此类规则放在http服务器主机配置中,而不要使用动态配置文件(“ .htaccess”)。 Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. 这些动态配置文件增加了复杂性,通常是导致意外行为,难以调试的原因,并且确实降低了http服务器的速度。 They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare). 仅当您无法访问真正的http服务器主机配置(阅读:真正便宜的服务提供商)或坚持编写自己的规则的应用程序(这显然是安全的噩梦)时,才提供它们作为最后的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM