【问题标题】:.htaccess rule for language detection in subdirectory.htaccess 子目录中语言检测的规则
【发布时间】:2020-11-23 19:04:23
【问题描述】:

我的网址是 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

【问题讨论】:

  • 你的测试成功了,它会抛出一个 500 内部服务器错误。
  • 是的,就是这样!还有一个问题,如果情况都一样,但我想在 /subdir/ 前面获得 (en/de) 怎么办?所以网址是myurl.com/en/subdir/login

标签: php regex .htaccess url-rewriting


【解决方案1】:

是的,就是这样!还有一个问题,如果情况都一样,但我想在 /subdir/ 前面加上 (en/de) 怎么办?所以网址是myurl.com/en/subdir/login:

在这种情况下,规则必须放在站点根目录 .htaccess 中,而不是 subdir/.htaccess 与此规则:

Options -MultiViews
RewriteEngine On

RewriteRule ^(en|de)/(subdir/login)/?$ $2.php?lng=$1 [L,QSA,NC]

【讨论】:

    猜你喜欢
    • 2013-05-27
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多