.htaccess 中的 RewriteRule 后重复附加 URL?

发布于 2024-12-12 03:03:56 字数 417 浏览 0 评论 0原文

这是我第一次为了 SEO 友好而重写 url。

这是我的 htaccess 规则:

RewriteEngine On
RewriteRule ratings/ ratings.php
RewriteRule regions/ regionlist.php
RewriteRule mobile/ mobile.php

出于某种原因,当我单击同一个链接两次时,该 url 会在地址栏中追加自身。这是一张 gif 图片,显示了这种情况:

https://i.sstatic.net/y5hqA.gif

这很糟糕吗?如果是,有人知道出了什么问题吗?

帮助将不胜感激!

谢谢大家

This is my first time re-writing urls to be SEO friendly.

Here's my htaccess rule:

RewriteEngine On
RewriteRule ratings/ ratings.php
RewriteRule regions/ regionlist.php
RewriteRule mobile/ mobile.php

For some reason, when I click the same link twice, the url will append itself in the address bar. Heres a gif image showing this happening:

https://i.sstatic.net/y5hqA.gif

Is this bad? If it is, does anyone know what's wrong ?

Help would be greatly appreciated!

Thanks everyone

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

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

发布评论

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

评论(4

驱逐舰岛风号 2024-12-19 03:03:56

将您的 RewriteRules 更改为:

RewriteRule ^([a-zA-Z]+)$ $1.php

并确保您的链接如下所示:

<a href="/ratings">ratings</a>

但如果您需要特定重写,请更改斜杠的位置

RewriteRule /ratings ratings.php
RewriteRule /regions regionlist.php
RewriteRule /mobile mobile.php

Change your RewriteRules to this:

RewriteRule ^([a-zA-Z]+)$ $1.php

and make sure that your links to be like this:

<a href="/ratings">ratings</a>

but if you need specific rewrites change the location of slash

RewriteRule /ratings ratings.php
RewriteRule /regions regionlist.php
RewriteRule /mobile mobile.php
旧话新听 2024-12-19 03:03:56

我认为这不是 htaccess 造成麻烦的地方...在我看来,您获取当前 URL 并附加单击项目的名称。相反,请从头开始创建 URL。

I think it's not the htaccess which couses trouble here... IMO you take current URL and append clicked item's name. Create the URL from scratch instead.

很快妥协 2024-12-19 03:03:56

如果您希望重写始终基于根目录,您可能需要在规则中添加前面的“/”(斜杠),

RewriteEngine On
RewriteRule /ratings ratings.php
RewriteRule /regions regionlist.php
RewriteRule /mobile mobile.php

这将强制重写规则将其附加到根 url。

if you want the rewrite to always be based off the root directory you may want to write your rules with a preceeding "/"(slash)

RewriteEngine On
RewriteRule /ratings ratings.php
RewriteRule /regions regionlist.php
RewriteRule /mobile mobile.php

This should force the rewrite rule to append this to the root url.

不必在意 2024-12-19 03:03:56

使用重定向:

redirect 301 /ratings /ratings.php

Use redirect:

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