[英]Rewrite URLs for Specific Language via PHP & htaccess
I need some htaccess rules which rewrite URIs like this: 我需要一些htaccess规则来重写URI,如下所示:
http://sub.domain.tld/en/about?a=1&b=2
to this: 对此:
http://sub.domain.tld/about.php?lang=en&a=1&b=2
or more simple: 或更简单:
http://sub.domain.tld/about.php?a=1&b=2&lang=en
No difference... 没有不同...
But the user should see the first URI not the converted one (shouldn't be redirected). 但是用户应该看到第一个URI,而不是转换后的URI(不应重定向)。
You may try this: 您可以尝试以下方法:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+) [NC]
RewriteCond %{QUERY_STRING} ([^/]+) [NC]
RewriteRule .* %2.php?%3&lang=%1? [L]
Maps silently 静默地图
http://sub.domain.tld/LangCode/FileName?key1=val1&key2=val2
With or without trailing slash. 带有或不带有斜杠。 Always displayed in browser's address bar, 始终显示在浏览器的地址栏中,
To: 至:
http://sub.domain.tld/FileName.php?key1=val1&key2=val2&lang=LangCode
For permanent redirect, replace [L]
with [R=301,L]
对于永久重定向,将[L]
替换为[R=301,L]
Here is the .htaccess code : 这是.htaccess代码:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule en/about?a=(.*)&b=(.*)$ about.php?lang=en&a=$1&b=$2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.