开发者

htaccess to redirect url with params

I have to redirect a url to another url with all its parameters using htaccess.

My incoming url will be something like this:

www.mydomain.com/book-it.jsp?id=3&var1=values&var2=value2...

and I want to get it in PHP (book-it.php开发者_如何学C) as something like this (with all its parameters):

www.mydomain.com/book-it.php?id=3&var1=values&var2=value2...

I was using JSP and from now on moving to PHP and we need to use same URL since this url is already published with my application and I can't change that now. I need to get that url and parameters to another file.


You have 2 main approaches:

1) Using Redirect directive:

Redirect 301 /book-it.jsp http://www.mydomain.com/book-it.php

2) Using mod_rewrite module (this needs to be placed in .htaccess in website root folder. If placed in Apache config file (inside <VirtualHost>, for example) the rules need to be modified slightly):

RewriteEngine On    
RewriteBase /
RewriteRule ^book-it\.jsp$ http://www.mydomain.com/book-it.php [QSA,NC,R=301,L]

Both of them will preserve query string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜