LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Apache .htaccess Redirect (https://www.linuxquestions.org/questions/linux-software-2/apache-htaccess-redirect-4175582759/)

blizunt7 06-21-2016 11:23 AM

Apache .htaccess Redirect
 
Hey all,
Having Trouble understanding how to issue a redirect (or rewritecond) in .htaccess.

We modified our site directories and pages are being served differently. Old pages are cached and we want to make sure the world can still access them. Need to dynamically redirect with our $_GET methods carrying over.


OLD URL: http://www.mysite.com/search.php?itm...4801&store=003

NEW URL: http://www.mysite.com/search/product..._num=001844801

All help is appreciated!

bathory 06-21-2016 12:11 PM

Hi,

You should use %{QUERY_STRING} for this kind of redirect.
If you're going to put rewrite stuff inside a .htaccess, then you can try the following:
Code:

RewriteEngine on

RewriteCond %{QUERY_STRING} ^itm_num=(.*)&store=(.*)
RewriteRule ^search.php search/product.php?store=%2&itm_num=%1

Regards

blizunt7 06-21-2016 12:40 PM

Most excellent, I see that working, except there is a conflict with an actual redirect rule I set, (Yes; I cause my own problems).

Code:

Redirect 301 /search.php http://www.mysite.com/search/index.php
So now the rewrite for the $_GET methods, actually loads me to:
Code:

http://www.mysite.com/search/index.php?store=003&itm_num=001844801
instead of
Code:

http://www.mysite.com/search/product.php?store=003&itm_num=001844801
Is there an way to exclude the "Redirect" if there are parameters set in the URL?

bathory 06-21-2016 01:49 PM

Maybe this:
Code:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^itm_num=(.*)&store=(.*)
RewriteRule ^search.php(.*) search/product.php?store=%2&itm_num=%1
RewriteRule ^search.php$  /search/index.php



All times are GMT -5. The time now is 06:27 AM.