LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-21-2016, 12:23 PM   #1
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Rep: Reputation: 30
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!
 
Old 06-21-2016, 01:11 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,910

Rep: Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890
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

Last edited by bathory; 06-21-2016 at 01:15 PM.
 
Old 06-21-2016, 01:40 PM   #3
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Original Poster
Rep: Reputation: 30
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?
 
Old 06-21-2016, 02:49 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 12,910

Rep: Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why am I not able to redirect using htaccess. It says too many redirect rules. swathi.akkineni Linux - Newbie 1 07-31-2015 04:20 PM
Redirect with htaccess chandranjoy Linux - Server 1 02-16-2011 08:40 AM
Apache htaccess redirect Jorkim Kustafin Linux - Server 2 07-23-2009 01:32 PM
Apache redirect with query string (.htaccess) penguintutor Linux - Server 2 09-20-2006 10:45 AM
Htaccess with a redirect Diode Linux - Networking 0 10-28-2003 07:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration