使用.htaccess重写多种语言的URL

编程入门 行业动态 更新时间:2024-10-24 14:19:15
本文介绍了使用.htaccess重写多种语言的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在一个多语言网站上工作,重写URL时遇到了一些麻烦。

I'm working on a multi-language website and I'm having a little trouble with rewriting URLs.

我必须有这样的东西:

1) mysite/en 2) mysite/en/product-one 3) mysite/en/product-one/id25/title-page-fake.html 4) mysite/en/login.php

URL重定向到:

1) mysite/index.php 2) mysite/index.php 3) mysite/item.php?id=25 4) mysite/login.php

我的.htaccess文件当前如下所示:

My .htaccess file currently looks like this:

RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^(.+/{0,0})$ $1/index.php [NC] RewriteRule ^([a-z0-9\-]+/)(.*)$ $2 [NC] RewriteRule ^id(\d+)\/.*$ item.php?id=$1&%{QUERY_STRING} [L]

可以工作,但是会抛出异常:

works, but throws exceptions:

超出请求由于可能的配置错误,限制了10个内部重定向。如有必要,使用 LimitInternalRecursion增加限制。

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

推荐答案

确定,请尝试以下规则:

Ok try this rule:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] # requirements 1 & 2 RewriteRule ^en(/product-one)?/?$ /index.php [L,NC] # requirement # 3 RewriteRule ^en/product-one/id([0-9]+) /item.php?id=$1 [L,NC,QSA] # requirement # 4 RewriteRule ^en/([^.]+\.php)$ /$1 [L,NC]

让我知道它是否有效我也可以建议其他规则。

Let me know if it works then I can suggest other rule also.

更多推荐

使用.htaccess重写多种语言的URL

本文发布于:2023-11-01 02:26:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547988.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   多种   语言   htaccess   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!