PHP 的“lang?=”的 mod_rewrite超过一页?
我目前在 .htaccess 文件中使用以下代码
RewriteEngine On
RewriteBase /
# Redirect languages
RewriteRule ^(en|es|zh\-tw|zh\-cn)/?$ index.php?lang=$1 [L]
使用该代码,每次我在 URL 末尾键入 /en
时,它都会将我重定向到 /?lang=en
(从 PHP 数组加载英文内容):
例如:
example/en
将我重定向到 example/?lang=en
,同时保留 example/en在网址中。
但我还有一个 thanks.php 页面,上面的代码显然只适用于 index.php 页面。
如何使重写规则适用于 index.php
和 thanks.php
页面?
I currently use the follwoing code in my .htaccess file
RewriteEngine On
RewriteBase /
# Redirect languages
RewriteRule ^(en|es|zh\-tw|zh\-cn)/?$ index.php?lang=$1 [L]
With that code, every time I type for instance, /en
at the end of the URL, it redirects me to /?lang=en
(loads the the English content from a PHP array):
For instance:
example/en
redirects me to example/?lang=en
while keeping example/en in the URL.
But I also have a thanks.php page and the code above clearly just work for the index.php page.
How can I make the rewrite rule to work for both index.php
and thanks.php
page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最直接的方法就是这样做:
如果您想让它更通用,您可以选择将文件列入白名单,如下所示:
...其中
(thanks)
将是您想要具有此功能的文件的管道分隔列表,或者您可以接受每个请求作为对现有 PHP 页面的传递:The most straight-forward way is just to do this:
If you want to make it more general, you have the option of white-listing files, like this:
...where
(thanks)
would be a pipe-delimited list of the files you wanted to have this functionality, or you can just accept every request as a pass-through to an existing PHP page: