1
URLにユーザーの言語設定を指定します。 .htaccess書き換えルールを使用して、URLにセグメントを追加することはできますか?URLにユーザの言語設定を強制する - 再書き込み?
URLは通常、言語が欠落している場合、私は自動的に英語の言語にデフォルトで指定したURLを変換したいこの構造
mysite.com/directory/en
mysite.com/directory/fr
mysite.com/directory/en/about_us.php
mysite.com/directory/fr/about_us.php
を持つ必要があります。
mysite.com/directory
>> should be transformed to mysite.com/directory/en
mysite.com/directory/about_us.php
>> should be transformed to mysite.com/directory/en/about_us.php
例:
RewriteEngine On
# don't redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule !^(fr|en)/ /... something...
# redirect
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
** * ** 1日以降の ** * ** * ****
誰かが私はマイケルのソリューションがやっている正確に理解することができますし、私は
mysite.com/directory
>> should be transformed to mysite.com/directory/en
mysite.com/directory/subdirectory/about_us.php
>> should be transformed to mysite.com/directory/en/subdirectory/about_us.php
...
# If the URL doesn't match /xx/otherstuff
# !^([a-z]{2}) - exactly two alpha characters not at the beginning of the string
# (.*)$ - store the result found above as $1
RewriteCond %{REQUEST_URI} !^([a-z]{2}/)(.*)$
# Rewrite to /en/
# ^(.+)$ - begins with
# http://%{HTTP_HOST}/en/$1 - replace with http://hostname/en
# L = Last Stop the rewriting process immediately and don't apply any more rules.
# R = Redirect Forces an external redirect, optionally with the specified HTTP status code
# QSA - Query String Append - forces the rewrite engine to append a query string part of the substitution string to the existing string
RewriteRule ^(.+)$ http://%{HTTP_HOST}/en/$1 [L,R,QSA]
マイケル - あなたの解決策を試しました。私は "http:// localhost/C:/xampp/htdocs/examples/MVC/en/index.php?url = index"を取得しました。 –
@MustaphaGeorge上記の変更を参照し、 'http:// $ {HTTP_HOST} 'を追加してください。 –
働いていない。 RTFMまでの時間。 –