HTACCESS 问:如何将index.php?id=directory/indext.html 重定向到一个目录?

发布于 2024-12-08 09:21:11 字数 621 浏览 0 评论 0原文

我似乎无法通过 .htaccess 将更复杂的链接重定向到目录(内部有 index.php)。由于 URL 又丑又长,我已经重建并更改了网站的文件:

旧:www.mysite.com/index.php?id=directory/index.html

新:www.mysite.com /目录/ (顺便说一下,其中包含index.php,而不再是.html)。

我还有很多目录,不仅仅是一个我想将旧链接重定向到新目录的目录,但它们在域名后面都有丑陋的index.php?id=somedirectory/index.html。

由于我彻底改变了我的网站,旧的和丑陋的 URL 打开了我的主页,丑陋的 URL 仍然在地址栏中,因为它们都曾经使用网站根目录中的主 .index.php 。对于 SEO 来说,重复内容是一大禁忌。

顺便说一句,我不使用数据库。我现在使用带有 include() 等的简单 PHP 文件。它不是一个带有会员帐户等的 WordPress 网站。我的网站静态多于动态。

我希望这不会太令人困惑。我并不是想缩短与 HTACCESS 的链接。我正在尝试永久重定向(301?)。

谢谢您的宝贵时间。

I can't seem to redirect more complex links to directories (with index.php inside) through .htaccess. I have reconstructed and changed files to my site because of the ugly and long URLs:

Old: www.mysite.com/index.php?id=directory/index.html

New: www.mysite.com/directory/
(with index.php in it, by the way, and not .html anymore).

I also have many directories and not just one that I would like to redirect old links to the new ones, but they all had the ugly index.php?id=somedirectory/index.html after the domain.

Since I have drastically changed my website, the old and ugly URLs open up my homepage with the ugly URL still in the address bar since they all used to use the main .index.php in the root of the site. That's a big no-no for SEO as duplicate content.

By the way, I don't use databases. I use simple PHP files with include() and such now. It's not a WordPress site with member accounts, etc. My website is more static than dynamic.

I hope this is not too confusing. I'm not trying to shorten links with HTACCESS. I'm trying to redirect permanently (301?).

Thank you for your time.

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

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

发布评论

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

评论(1

罗罗贝儿 2024-12-15 09:21:11

这应该可以:

RewriteRule ^mysite.com/(.+) mysite.com.index.php?id=$1/index.html [NC]

它对我有用!

您还需要:

Options +FollowSymLinks
RewriteEngine on

上面的声明。

This should do:

RewriteRule ^mysite.com/(.+) mysite.com.index.php?id=$1/index.html [NC]

It works for me!

You will also need:

Options +FollowSymLinks
RewriteEngine on

Above the previous statement.

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