htaccess-跳过第一个文件夹 [英] htaccess - skip first folder

查看:88
本文介绍了htaccess-跳过第一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有一个这样的多语言站点:

If you have a multilingual site like this:

example.com/en/some-folder/some-file

example.com/en/some-folder/some-file

example.com/ru/some-folder/some-file

example.com/ru/some-folder/some-file

example.com/et/some-folder/some-file

example.com/et/some-folder/some-file

是否可以将"ru","en"和"et"捕获到$ lang这样的PHP变量中,并且同时拥有仅使用htaccess的目录,像这样?

Would it be possible to catch the "ru","en" and "et" into a PHP variable like $lang, and, at the same time, have a directory that looks like this using only htaccess?

htdocs/some-folder/some-file.php

htdocs/some-folder/some-file.php

代替:

htdocs/en/some-folder/some-file.php

htdocs/en/some-folder/some-file.php

htdocs/ru/some-folder/some-file.php

htdocs/ru/some-folder/some-file.php

htdocs/et/some-folder/some-file.php

htdocs/et/some-folder/some-file.php


我希望不必为每种语言重新创建所有文件夹和文件.但是我也想将URL中的语言捕获到一个变量中,然后忽略它,就好像它不存在一样.


I want to be able to not have to re-create all folders and files for each of the languages. But I also want to catch the language in the URL into a variable, and and ignore it as if it does not exist.

推荐答案

您可以在.htaccess中使用它:

RewriteEngine on 
RewriteRule ^(en|ru|et)(/.*)$ $2?lang=$1 [NC,L,QSA]

example.com/en/some-folder/some-file.php重写为example.com/some-folder/some-file.php?lang=en

这篇关于htaccess-跳过第一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆