htaccess - skip first folder

本秂侑毒 提交于 2019-12-10 23:53:57

问题


If you have a multilingual site like this:

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

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

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

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

Instead of:

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

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

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


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.


回答1:


You can use that in your .htaccess:

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

Rewrite example.com/en/some-folder/some-file.php to example.com/some-folder/some-file.php?lang=en



来源:https://stackoverflow.com/questions/33585428/htaccess-skip-first-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!