重写 Apache RewriteRule?

发布于 2024-09-29 06:34:11 字数 604 浏览 1 评论 0原文

在我的应用程序的 .htaccess 文件中,我有以下内容:

Options -Indexes

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) index.php

一个非常轻量级的文件,通过 index.php 放置所有不匹配的请求。

然而,这个应用程序是一个社交网站,我的任务是制作多语言版本。因此,像 www.example.com/profile/martin 这样的 URL 需要转换为西班牙语,因此会变成 www.example.com/perfil/martin

因此,我的问题是:是否可以重写RewriteRule?在本例中,我想将 /perfil/martin 重写为 /profile/martin,但随后将 /profile/martin 传递给 index.php

In my application's .htaccess file I have the following:

Options -Indexes

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+) index.php

A very lightweight file that puts all unmatched requests through index.php.

However, this application is a social networking website that I've been tasked with making multi-lingual. Therefore, URLs like www.example.com/profile/martin need to be converted in to say, Spanish, and will therefore become www.example.com/perfil/martin.

Therefore, my question is: is it possible to rewrite a RewriteRule? In this instance, I want to rewrite /perfil/martin to /profile/martin, but then have /profile/martin passed to index.php.

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

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

发布评论

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

评论(1

初吻给了烟 2024-10-06 06:34:11

在 'RewriteRule ^(.+) index.php' 行之前添加以下行应该可以实现您想要的效果。

RewriteRule perfil/(.*) profile/$1

我认为您应该在 Web 应用程序的 URL 路由代码中执行此操作,而不是在 htaccess 文件中执行此操作。

Adding the following line before the 'RewriteRule ^(.+) index.php' line should achieve what you want.

RewriteRule perfil/(.*) profile/$1

I'd argue that you should be doing this in your web app's URL routing code though, rather than the htaccess file.

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