重写 Apache RewriteRule?
在我的应用程序的 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 '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.