htaccess 将目录名重定向到参数 [英] htaccess Redirect directory name to parameter

查看:33
本文介绍了htaccess 将目录名重定向到参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像这样重定向所有路径:

I would like to redirect all paths like this:

myurl.com/worldwide/en
myurl.com/worldwide/pt
myurl.com/worldwide/de

到:

myurl.com/worldwide/index.php?lang=en
myurl.com/worldwide/index.php?lang=pt
myurl.com/worldwide/index.php?lang=de

只是为了清除 /worldwide

实际上理想情况下,我想保留原始 url(例如 myurl.com/worldwide/de)但加载相同的 php 文件,并将语言目录作为参数,但不确定这是否可行?

Actually ideally I would like to keep the original url (e.g. myurl.com/worldwide/de) but load the same php file with the language directory as a param but not sure if this is possible?

谢谢

推荐答案

使用此代码

RewriteEngine On
RewriteBase /worldwide/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?lang=$1 [L,QSA]

如果这对您有帮助,请告诉我

Please let me know if this helps you

这篇关于htaccess 将目录名重定向到参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆