.htaccess,将所有 PHP 变量重写到文件夹
我遇到这个问题了。我想将所有 php 变量写入文件夹。例如:
www.mypage.com/en/shows/1/
到
www.mypage.com/index.php?language=en§ion=shows&item=1
>
或
www.mypage.com/en/home/
到
www.mypage.com/index.php?language=en§ion=home
这是我得到的:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)/(.*)/$ index.php?language=$1§ion=$2
RewriteRule (.*)/(.*)/(.*)/$ index.php?language=$1§ion=$2&item=$3
它完美地与www.mypage.com/en/home/
到
www.mypage.com/index.php?language=en§ion=home
但是当我尝试使用 www.mypage.com/en/shows/1/
到
www.mypage.com/index.php?language=en§ion=shows&item=1
var 语言消失。我阅读了这里已经发布的一些答案并找到了一些教程,但说实话我不太了解。
感谢您的耐心等待,我是一个完全的新手。 非常感谢。
I got this problem. I want to write ALL my php vars to folders. For example:
www.mypage.com/en/shows/1/
to
www.mypage.com/index.php?language=en§ion=shows&item=1
or
www.mypage.com/en/home/
to
www.mypage.com/index.php?language=en§ion=home
This is what I got:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)/(.*)/$ index.php?language=$1§ion=$2
RewriteRule (.*)/(.*)/(.*)/$ index.php?language=$1§ion=$2&item=$3
It works perfectly with www.mypage.com/en/home/
to
www.mypage.com/index.php?language=en§ion=home
but when I try with www.mypage.com/en/shows/1/
to
www.mypage.com/index.php?language=en§ion=shows&item=1
the var laguage disapears. I read some of the answers already posted here and find a couple of tutorials but to be honest I don't understand too much.
Thanks for your patience, I am a complete newbie.
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为主要问题是您的第一个 RewriteRule 将始终匹配,而不是第二个。匹配
(.*)/(.*)/(.*)/$
的内容也将始终匹配(.*)/(.*)/$
,因为后者并不关心它之前的内容。理想情况下,您希望在开头放置一个
^
来阻止这种情况,但如果您不能或它不起作用,您可以随时尝试反转规则,以便具有三个的区域有机会首先匹配。尽管重写应该阻止第二条规则匹配,但最好在它们后面添加[L]
,除非有其他原因不能这样做。[L]
表示如果匹配,则不会尝试匹配任何其他规则。I think the main issue is that your first RewriteRule will always match instead of your second one. Something that matches
(.*)/(.*)/(.*)/$
will always match(.*)/(.*)/$
also, because the latter doesn't care what comes before it.Ideally, you would want to put a
^
at the beginning to stop this, but if you can't or it doesn't work, you could always try just reversing the rules so that the one with three areas gets a chance to match first. And although the rewrite should prevent the second rule from matching, it would be good practice to add[L]
after them both, unless there's another reason you can't.[L]
means that if it matches, it won't try matching any other rules.试试这个,
我假设有 2 个字符的语言代码
Try this instead
I am assuming a 2 character language code