Php 如何使用.htaccess重定向到以尾随斜杠作为语言参数的站点页面

Php 如何使用.htaccess重定向到以尾随斜杠作为语言参数的站点页面,php,.htaccess,mod-rewrite,redirect,slash,Php,.htaccess,Mod Rewrite,Redirect,Slash,我有一条无法正确重定向的规则: #redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$ RewriteCond %{REQUEST_URI} !public/ RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es

我有一条无法正确重定向的规则:

#redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es [L]
在内部,没有收到参数页,因此站点显示主页。我不确定这条规则是否有误,或者它是否与其他运行良好的规则相冲突,或者它是否是一个顺序问题

非常感谢您的帮助。 提前谢谢

下面是我的网站根目录下的完整htaccess文件,以防您想查看它

Options +FollowSymlinks
RewriteEngine on

DirectoryIndex index.php

#Adds www to the domain
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

#redirect from www.mysite.com/es to www.mysite.com/public/index.php?lang=es
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule /es$ public/index.php?lang=es [L]

#redirect from www.mysite.com/en to www.mysite.com/public/index.php?lang=en
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule /en$ public/index.php?lang=en [L]

#redirect from www.mysite.com/ to www.mysite.com/public/index.php
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(/)?$ public/index.php [L]

#redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es [L]

#redirect from www.mysite.com/page-NAME to www.mysite.com/public/index.php?page=NAME
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule page-(.*)$ public/index.php?page=$1 [L]

#redirect from www.mysite.com/ to www.mysite.com/public/
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/$1 [L]

好的,发现问题似乎,这确实是一个订单问题,这是一种似乎有效的方式,希望这有助于解决同样问题的人

Options +FollowSymlinks
RewriteEngine on

DirectoryIndex index.php

#Adds www to the domain
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

#redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es
RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es [L]

#redirect from www.mysite.com/page-NAME to www.mysite.com/public/index.php?page=NAME
RewriteRule page-(.*)$ public/index.php?page=$1 [L]


#redirect from www.mysite.com/es to www.mysite.com/public/index.php?lang=es
RewriteRule /es public/index.php?lang=es [L]

#redirect from www.mysite.com/en to www.mysite.com/public/index.php?lang=en
RewriteRule /en public/index.php?lang=en [L]

#redirect from www.mysite.com/ to www.mysite.com/public/index.php
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(/)?$ public/index.php [L]


#redirect from www.mysite.com/ to www.mysite.com/public/
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/$1 [L]

更新:这似乎是一个冲突问题,因为如果我删除重定向www.mysite.com/es和www.mysite.com/en的规则,页面将正确加载,因此我想问题是如何使所有这些规则一起工作