Php 带有语言和页面参数的htaccess重定向url

Php 带有语言和页面参数的htaccess重定向url,php,.htaccess,redirect,mod-rewrite,Php,.htaccess,Redirect,Mod Rewrite,我真的迷失在重定向htaccess的所有规则中,我找不到解决问题的完美方案。 我正在尝试重定向我的URL,如下所示: http://mywebpage.eu/path/to/site/LANGUAGE/PAGE 应该重定向到谁 http://mywebpage.eu/path/to/site/index.php?lang=LANGUAGE&page=PAGE http://mywebpage.eu/path/to/site/index.php?lang=LANGUAGE&pa

我真的迷失在重定向htaccess的所有规则中,我找不到解决问题的完美方案。 我正在尝试重定向我的URL,如下所示:

http://mywebpage.eu/path/to/site/LANGUAGE/PAGE
应该重定向到谁

http://mywebpage.eu/path/to/site/index.php?lang=LANGUAGE&page=PAGE
http://mywebpage.eu/path/to/site/index.php?lang=LANGUAGE&page=
http://mywebpage.eu/path/to/site/index.php?lang=&page=PAGE
但有时他们可能会像这样没有页面或语言

http://mywebpage.eu/path/to/site/LANGUAGE/
http://mywebpage.eu/path/to/site/PAGE/
应该重定向到谁

http://mywebpage.eu/path/to/site/index.php?lang=LANGUAGE&page=PAGE
http://mywebpage.eu/path/to/site/index.php?lang=LANGUAGE&page=
http://mywebpage.eu/path/to/site/index.php?lang=&page=PAGE
(所有这些示例都可以以“/”结尾,也可以不结尾)

当我最终得到某个正在工作的东西的一部分时,我所有的css/images/js/include(php)都出现了404错误,因为添加了虚拟子文件夹“/LANGUAGE/”

非常感谢您的帮助。

请这样做:

RewriteEngine on
RewriteBase /path/to/site/

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([a-z]{2})(?:/(.*))?/?$ index.php?lang=$1&page=$2 [L,QSA]

RewriteRule ^(\w+)/?$ index.php?lang=&page=$1 [L,QSA]
对于css/js/图像,您可以在页面HTML的
部分下方添加此选项:
,以便每个相对URL都是从该基本URL解析的,而不是从当前页面的URL解析的。

非常感谢dude:)看起来很完美!