为同一文件夹中的多个 url 创建重写规则

发布于 2024-08-25 03:20:03 字数 954 浏览 2 评论 0原文

我们的客户要求我将我们创建的网站转换为 SEO 友好的 url 格式。我已经设法解决了这个问题,但遇到了在同一文件夹中具有相同网址的问题。

我正在尝试重写以下网址,

  1. /review/index.php?cid=intercasino
  2. /review/submit.php?cid=intercasino
  3. /review/index.php?cid=intercasino&page=2#reviews

我想得到他们到

  1. /review/intercasino
  2. /submit-review/intercasino
  3. /review/intercasino/2#reviews

我几乎已经使用以下规则让它工作了,

RewriteRule (submit-review)/(.*)$ review/submit.php?cid=$2 [L]
RewriteRule (^review)/(.*) review/index.php?cid=$2

您可能已经看到的问题是 /submit-review 重写为 /评论,反过来会被重写为index.php,因此我的评论提交页面会丢失,而不是我的索引页面。我认为放置 [L] 会阻止调用第二条规则,但它似乎在两次单独的传递中重写了两个 url。我也尝试过 [QSE],并且 [S=1]

我宁愿不必将我的文件移动到不同的文件夹中以使重写工作,因为这看起来太糟糕了。如果有人能给我一些关于如何区分这些相似网址的指示,那就太好了!

谢谢 (参考:http://httpd.apache.org/docs/2.0/mod /mod_rewrite.html

I have been asked by our client to convert a site we created into SEO friendly url format. I've managed to crack a small way into this, but have hit a problem with having the same urls in the same folder.

I am trying to rewrite the following urls,

  1. /review/index.php?cid=intercasino
  2. /review/submit.php?cid=intercasino
  3. /review/index.php?cid=intercasino&page=2#reviews

I would like to get them to,

  1. /review/intercasino
  2. /submit-review/intercasino
  3. /review/intercasino/2#reviews

I've almost got it working using the following rule,

RewriteRule (submit-review)/(.*)$ review/submit.php?cid=$2 [L]
RewriteRule (^review)/(.*) review/index.php?cid=$2

The problem, you may already see, is that /submit-review rewrites to /review, which in turn gets rewritten to index.php, thus my review submission page is lost in place of my index page. I figured that putting [L] would prevent the second rule being called, but it seems that it rewrites both urls in two seperate passes. I've also tried [QSE], and [S=1]

I would rather not have to move my files into different folders to get the rewriting to work, as that just seems too much like bad practise. If anyone could give me some pointers on how to differentiate between these similar urls that would be great!

Thanks
(Ref: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html)

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

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

发布评论

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

评论(2

勿挽旧人 2024-09-01 03:20:05

我的朋友找到了解决这个问题的方法。

RewriteRule review/submit.php - [L]

将抓住第一个重写,然后阻止下一个重写,辛苦了!

My friend found a solution to this one.

RewriteRule review/submit.php - [L]

Will catch the first rewrite and then prevent the next one, worked a treat!

深陷 2024-09-01 03:20:04

我要做的就是直接将 /submit-review/ 发布到自身(或 php 文件),然后从 PHP 文件中提交重定向。

在重定向等时强制 htaccess 维护帖子值可能很困难

What I would do, is make /submit-review/ post directly to itself (or a php file) then once submitted redirect from within the PHP file.

It can be hard to force htaccess to maintain post values whilst redirecting etc

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