重定向动态URL包括htaccess的查询字符串 [英] Redirect dynamic urls including querystring with htaccess
问题描述
我需要重定向的URL一些从旧版本的网站,以新的URL。 我没有发现的问题,简单的网址,但我不能与查询字符串的URL工作:
重定向301 /product_detail.php?id=1 http://www.mysite.com/product/permalink
这只是返回一个404,没有找到。
我也试过上的Silex路线(PHP的微架构我使用),但它也不能工作:
$ APP->得到('?/ product_detail.php ID = {ID},函数($ id)的使用($应用程序){
$ prodotto =产品:: getPermalink($ ID);
返回$ APP->重定向($应用['url_generator'] - >产生(产品,阵列(永久链接'=> $ prodotto)));
});
有没有一些htaccess的规则的方式,让查询字符串被认为是URL的一部分,让它正确地重定向?
感谢你。
重定向301 /product_detail.php?id=1
http://www.mysite.com/product/permalink
重定向
是一个mod_alias中的不恰当操作查询字符串:
启用mod_alias被设计成处理简单的URL操作任务。对于更复杂的任务,比如操作查询字符串,请使用提供了mod_rewrite的工具。
因此,的mod_rewrite
应使用。同样的例子在根目录中选择一个.htaccess文件将是这样的:
选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{REQUEST_URI} ^ / product_detail \ .PHP [NC]
的RewriteCond%{REQUEST_URI}!/产品/永久[NC]
重写规则。* /产品/永久[R = 301,NC,L]
重定向
http://www.mysite.com/product_detail.php?id=1
要:
http://www.mysite.com/product/permalink?id=1
查询被自动添加到替换URL。
有关内部映射,替换[R = 301,NC,L]与[NC,L]
I need to redirect some urls from an old version of a web-site to new urls. I didn't find problem with simple urls, but I can't get the urls with querystrings to work:
Redirect 301 /product_detail.php?id=1 http://www.mysite.com/product/permalink
It simply returns a 404, not found.
I'm also tried with a route on Silex (the PHP micro-framework I'm using) but it didn't work either:
$app->get('/product_detail.php?id={id}', function($id) use ($app) {
$prodotto = Product::getPermalink($id);
return $app->redirect($app['url_generator']->generate('product',array('permalink'=>$prodotto)));
});
Is there a way with some htaccess rule to let the query string be considered as a part of the url and let it be redirected properly?
Thank you.
Redirect 301 /product_detail.php?id=1
http://www.mysite.com/product/permalink
Redirect
is a mod_alias directive not appropriate to manipulate query strings:
mod_alias is designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_rewrite.
Extracted from Apache mod_alias docs
So, mod_rewrite
should be used. The same example in one .htaccess file in root directory would be something like this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/product_detail\.php [NC]
RewriteCond %{REQUEST_URI} !/product/permalink [NC]
RewriteRule .* /product/permalink [R=301,NC,L]
It redirects
http://www.mysite.com/product_detail.php?id=1
To:
http://www.mysite.com/product/permalink?id=1
The query was automatically appended to the substitution URL.
For internal mapping, replace [R=301,NC,L] with [NC,L]
这篇关于重定向动态URL包括htaccess的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!