简体   繁体   English

使用.htaccess(Apache)为多语言站点的URL重写提供帮助

[英]help with URL rewrite for a multilanguage site with .htaccess (Apache)

I have a multilanguage site and I'm trying to rewrite the URL's with a fake directory something like this: 我有一个多语言站点,并且正在尝试使用伪目录重写URL,如下所示:

http://localhost/theSite/page.php?id=param&cat=param?lang=en,fr,es to http://localhost/theSite/(en|fr|es)/page/param/param http://localhost/theSite/page.php?id = param&cat = param?lang = en,fr,eshttp:// localhost / theSite /(en | fr | es)/ page / param / param

.htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(fr|en|en)/(.*) $2.php?id=$1&cat=$2&lang=$3 [NL,QSA]

This resolves as a 404 error. 解决为404错误。

Any help will be apreciate. 任何帮助将不胜感激。

RewriteRule ^(en|fr|es)/(.*?)/(.*?)/(.*) $2.php?id=$3&cat=$4&lang=$1 [NC,QSA]

I suppose you meant NC (no case), not NL . 我想您的意思是NC (无大小写),而不是NL You referred to capture groups that didn't exist and repeated $2 . 您提到了不存在的捕获组,并重复了$2

You're second capture will capture everything until the end of the URL. 第二次捕获将捕获所有内容,直到URL末尾。 So it is possible you are doubling up on the extension or the wrong directory. 因此,您可能加倍了扩展名或错误的目录。

Although it shouldn't affect the redirect, you don't have a third capture, so where is $3 ? 尽管它不应该影响重定向,但是您没有第三次捕获,因此$3在哪里?

Look at your headers and see where it is really redirecting to and comment back. 查看您的标头,查看它真正重定向到的位置并进行评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM