使用 .htaccess 或任何其他方法调整动态生成的链接?

发布于 2024-09-10 06:02:32 字数 780 浏览 0 评论 0原文

我有一个电子商务网站(使用 ecommercetemplates 购物车 PHP 模板创建),在目录页面上有时会有一些页面在底部编号。例如,这些页面的链接采用以下形式:- /product.php?cat=27&pg=2,尽管主页已映射到:- /widgets< /code> 在 .htaccess 文件中使用重写规则。

为了保持一致性和简单性,我希望页面如下:- /widgets?pg=2。我在这个论坛中询问如何做到这一点,并找到了以下解决方案:-

RewriteRule ^widgets$ products.php?cat=27 [QSA] 

问题是,尽管上述重写规则按我想要的方式工作,目录页面上的当前链接仍然指向,例如:- /product .php?cat=27&pg=2。为了转到 /widgets?pg=2,我必须在浏览器中输入此内容。

所以我的问题是:如何更改目录页面上动态生成的当前链接?是否可以在 .htaccess 中输入任何进一步的规则,或者是否有其他解决方案来解决此问题?以下是产品页面的 PHO 代码:- http://freetexthost.com/3ubiydspzm

在上面的链接中,如果您搜索“writepagebar”,我认为这是完成“下一页”、“上一页”和“页码”的地方。

I have an e-commerce website (created with a ecommercetemplates shopping cart PHP template) and on the catalogue pages there are, at times, a few pages which are numbered at the bottom. The links to these pages are, for example, in the form:- /product.php?cat=27&pg=2 despite the main page having been mapped to:- /widgets using a rewrite rule in a .htaccess file.

For the sake of consistency and simplicity, I would like the pages to be as:- /widgets?pg=2. I asked in this forum how to do this and found the following solution:-

RewriteRule ^widgets$ products.php?cat=27 [QSA] 

The problem is that despite the above rewrite rule working as I wanted, the current links on the catalogue page still point to, for example:- /product.php?cat=27&pg=2. In order to go to /widgets?pg=2, I have to enter this in the browser.

So my question is: How do I change the current links on the catalogue page, which are dynamically generated? Are there any further rules which can be entered in .htaccess or is there any other solution to this problem? The following is the PHO code for the product page:- http://freetexthost.com/3ubiydspzm.

In the link above, if you do a search for 'writepagebar', I think this is where the 'next page', 'previous page', and the 'page numbers' are done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゞ花落谁相伴 2024-09-17 06:02:32

您有几个选择:

其中大多数需要的不仅仅是 .htaccess 重写规则。

  • 您可以修改 writepagebar 函数来为您输出友好的 URL。 (并更改可能链接到此产品页面的任何其他函数。)
  • 您可以缓冲整个页面的输出并对其进行字符串替换。 (请参阅 PHP 手册中的 ob_start 和 ob_get_clean。)
  • 您可以使用 301 重定向将丑陋的 URL 重定向到漂亮的 URL。 (链接将保持不变,但您的友好 URL 会获得 SEO 功劳并显示在浏览器中。)
    • 或者您可以尝试这个丑陋的 mod_rewrite hack,我不能保证它可以在您的服务器或应用程序上运行。

Hack:(

RewriteCond %{QUERY_STRING} (.*)(cat=27\&)(.*) [OR]
RewriteCond %{QUERY_STRING} (.*)(cat=27)(.*)
RewriteCond %{THE_REQUEST} !widgets
RewriteRule ^products.php$ widgets?%1%3 [R=301,L]

这可能需要重写基础选项)
http://services.rrbits.com/products.php?cat=27&pg=2(示例链接。)

You have a couple of options:

Most of them require more than just .htaccess rewrite rules.

  • You can modify the writepagebar function to output the friendly URL for you. (And change any other function that might link to this products page.)
  • You can buffer the entire page's output and do a string replace on it. (See ob_start and ob_get_clean in the PHP manual.)
  • You can redirect ugly URLs to pretty ones with a 301 redirect. (The links will stay the same, but your friendly URLs get the SEO credit and show up in the browser.)
    • Or you can try this ugly mod_rewrite hack that I can't guarantee will work on your server or with your application.

Hack:

RewriteCond %{QUERY_STRING} (.*)(cat=27\&)(.*) [OR]
RewriteCond %{QUERY_STRING} (.*)(cat=27)(.*)
RewriteCond %{THE_REQUEST} !widgets
RewriteRule ^products.php$ widgets?%1%3 [R=301,L]

(This might need the rewrite base option)
http://services.rrbits.com/products.php?cat=27&pg=2 (Example link.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文