php - .htaccess 子目录中语言检测的规则
问题描述
我有一个网址是https://www.myurl.com/subdir/language/login.php
.
“语言”参数不是现有的子文件夹。文件夹结构为:
root/subdir/.htaccess
如您所见,.htaccess 文件位于https://www.myurl.com/subdir/.htaccess
我想做一个 .htaccess 重写规则,以便将调用的 uri:(
https://www.myurl.com/subdir/en/login
不带 .php)
更改为:
https://www.myurl.com/subdir/login.php?lng=en
我目前的方法是:
# MultiViews must be disabled for the rewrite to work
Options -MultiViews
# Turn on the rewriting engine
RewriteEngine On
RewriteBase /subdir/
RewriteRule (en|de)(/login)$ login.php?lng=$1 [L]
但是当我调用 URI 时,https://www.myurl.com/subdir/en/login
我得到一个 http 错误代码404
。
解决方案
对,就是那样!还有一个问题,如果场景都是一样的,但我想
(en/de)
在前面/subdir/
呢?所以网址是myurl.com/en/subdir/login
:
在这种情况下,必须将规则放在站点根目录 .htaccess 中,而不是subdir/.htaccess
使用此规则:
Options -MultiViews
RewriteEngine On
RewriteRule ^(en|de)/(subdir/login)/?$ $2.php?lng=$1 [L,QSA,NC]
推荐阅读
- mysql - 从 json 字段 mysql 中的键、值对列表中提取键
- c# - Signin-oidc 页面直接访问错误与关联 - 如何重定向?
- ios - 如何在 iOS 上禁用 Xamarin 中的手势?
- reactjs - React - 显示“localStorage 未定义”错误
- ios - Xcode 10 中的 Instruments iOS 自动布局工具在哪里?
- android - 从具有 FLAG_ACTIVITY_NEW_TASK 的活动返回导航到具有 FLAG_ACTIVITY_NEW_DOCUMENT 的活动不起作用
- ios - 如何从 info.plist 获取静态框架的版本?或任何其他方式?
- python - python - 读取stm发送的串行数据
- azure - 我们如何通过门户本身或以编程方式(powershell)在 azure 帐户中找到当前用户会话的数量?
- youtube-api - 在 YouTube Analytics API v2 中按份额排序