例如,我的根目录中有两个文件: one.php 和 two.php 。我想通过这些URL到达它们,而不必实际拥有物理目录en + de。
I have for example two files in my root directory: one.php and two.php. I would like to reach them through these urls without having to actually have the physical directories en+de.
- mydomain/en/ 一个
- mydomain / en / 两个
- mydomain/de/ 一个
- mydomain / de / 两个
- mydomain/en/one
- mydomain/en/two
- mydomain/de/one
- mydomain/de/two
因此,第一个目录将被忽略,并仅通过GET变量传递php文件的语言设置,第二个目录是不带扩展名的php文件。
So the first directory would be "ignored" and just pass a GET variable with the language setting to the php-file, second directory is the php-file without extension.
到目前为止,这是我在htaccess中使用的扩展名:
This is what I'm using in my htaccess to loose the file extension so far:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php更新/解决方案 : .htaccess语言检测规则 ,这似乎
UPDATE/SOLUTION This is quite useful: .htaccess rule for language detection and this seems to pretty much do what I wanted:
RewriteRule ^(en|de|fr)/(.*)$ $2?lang=$1 [L,QSA] RewriteRule ^(.*)$ $1?lang=en [L,QSA]一个其他问题 对于mydomain/en/ 一个 / id45 如果我想将id45作为变量传递给 one.php ,我必须在htaccess中添加哪一行?
ONE MORE ADDITIONAL QUESTION For mydomain/en/one/id45 If I wanna pass id45 as a variable to one.php what line in htaccess do I have to add?
推荐答案您可以尝试以下规则:
DirectoryIndex index.php index.html DirectorySlash On Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$2.php -f RewriteRule ^(en|de|fr)/([^/]+)(?:/(.*)|)$ $2.php?lang=$1&var=$3 [L,QSA,NC] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.+?)/?$ $1.php [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z]{2})/?$ index.php?lang=$1 [L,QSA,NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/?$ $1?lang=en [L,QSA]更多推荐
使用htaccess URLrewrite设置语言
发布评论