簡體   English   中英

.htaccess 子目錄語言檢測規則

[英].htaccess rule for language detection in subdirectory

我有一個 URL,它是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

對,就是那樣! 還有一個問題,如果場景都一樣,但我想在/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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM