我需要从:
重定向http://my-site.com/index.php?ean={any_number}
例如:http://my-site.com/index.php?ean=123
:
http://my-site.com/b={any_number}
例如:http://my-site.com/b=123
注意,我需要使用REDIRECT
函数,而不是RewriteRule
。
任何想法?非常感谢!
try this
RewriteCond %{REQUEST_URI} ^index.php$
RewriteCond %{QUERY_STRING} ^ean=([0-9]+)$
RewriteRule ^(.*)$ http://my-site.com/b=%1 [R,L]
使用PHP,您可以使用header()
执行重定向。
<?php
//--- index.php snippet ---
if (isset($_GET['ean'])) {
header("Location: http://yoursite.com/b=".intval(trim($_GET['ean'])));
exit(0);
}
如果基于URI而不是参数进行重定向,则可以使用RedirectMatch在中执行重定向。htaccess (例如, yoursite.com/ean/12345 )。
的代码。Htaccess 应该是这样的:
RedirectMatch 301 /ean/(.*) /b=$1
所以,最后我决定在PHP
中重定向header(Location: www.your-site.com)
函数。谢谢你。