Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

htaccess 301 redirect not working

Posted on 2013-05-16
7
356 Views
Last Modified: 2013-05-17
Hi all :)

i have a page available at 2 URLs:

http://www.futureharvesteurope.com/index.php?mod=prod&p=55
and
http://www.futureharvesteurope.com/index.php?mod=prod&desc=Ozone-plug-in&p=55

i need to redirect the first url to the second one that has the keywords in it. (Ozone-plug-in)

this is my full htaccess that is not doing the job:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RedirectMatch 301 http://www.futureharvesteurope.com/index.php?mod=prod&p=55 http://www.futureharvesteurope.com/index.php?mod=prod&desc=Ozone-plug-in&p=55

RewriteCond %{THE_REQUEST} ^.*\/index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
RewriteCond %{http_host} ^futureharvesteurope.com$ [nc]
RewriteRule ^(.*)$ http://www.futureharvesteurope.com/$1 [r=301,nc,L] 

Open in new window

0
Comment
Question by:helpchrisplz
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:adrian_brooks
ID: 39171662
First thing I would check is that you have the mod_rewrite module loading in apache.

Next, check your .htaccess file's owner/group and permissions. I am not 100% certain on this, but I believe that the file has to be owned/grouped to the same thing as the apache service and the permissions I think need to be 0700 or 0755.

~AB
0
 
LVL 82

Expert Comment

by:hielo
ID: 39171726
try:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING}     ^(mod=[^&]*&p=[^&]*)$    [OR,NC]
RewriteCond %{QUERY_STRING}     ^(p=[^&]*&mod=[^&]*)$    [NC]
RewriteRule ^/?index.php$       /index.php?%1&desc=Ozone-plug-in      [NC,L,R=301]

Open in new window

0
 
LVL 1

Author Comment

by:helpchrisplz
ID: 39171921
yes that seems to work. I have been looking at it and trying to figure out how to adapt it to other pages i need redirecting like:

http://www.futureharvesteurope.com/index.php?mod=prod&desc=&p=5

to

http://www.futureharvesteurope.com/index.php?mod=prod&desc=ph-monitor-ph-tester&p=5

is there a way that i can say if url has p=5 then redirect to: desc=ph-monitor-ph-tester&p=5

its just that i can't see a way of reusing the code.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 82

Expert Comment

by:hielo
ID: 39172088
>>is there a way that i can say if url has p=5 then redirect to: desc=ph-monitor-ph-tester&p=5
try:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING}     (.*\bp=5\b.*)    [NC]
RewriteRule ^/?index.php$       /index.php?%1&desc=ph-monitor-ph-tester      [NC,L,R=301]

RewriteCond %{QUERY_STRING}     ^(mod=[^&]*&p=[^&]*)$    [OR,NC]
RewriteCond %{QUERY_STRING}     ^(p=[^&]*&mod=[^&]*)$    [NC]
RewriteRule ^/?index.php$       /index.php?%1&desc=Ozone-plug-in      [NC,L,R=301]
0
 
LVL 1

Author Comment

by:helpchrisplz
ID: 39174230
i used that code but when going to:
http://www.futureharvesteurope.com/index.php?mod=prod&desc=&p=5

The url changes to this:
http://www.futureharvesteurope.com/index.php?mod=prod&desc=&p=5&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester&desc=ph-monitor-ph-tester

using:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /


RewriteCond %{QUERY_STRING}     (.*\bp=5\b.*)    [NC]
RewriteRule ^/?index.php$       /index.php?%1&desc=ph-monitor-ph-tester      [NC,L,R=301]

RewriteCond %{QUERY_STRING}     ^(mod=[^&]*&p=[^&]*)$    [OR,NC]
RewriteCond %{QUERY_STRING}     ^(p=[^&]*&mod=[^&]*)$    [NC]
RewriteRule ^/?index.php$       /index.php?%1&desc=Ozone-plug-in      [NC,L,R=301]


RewriteCond %{THE_REQUEST} ^.*\/index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
RewriteCond %{http_host} ^futureharvesteurope.com$ [nc]
RewriteRule ^(.*)$ http://www.futureharvesteurope.com/$1 [r=301,nc,L] 

Open in new window


It must 301 it then see it has the p=5 and redo it again and again?
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 39174973
>>It must 301 it then see it has the p=5 and redo it again and again?
agree. Try:
RewriteCond %{QUERY_STRING}     (.*\bp=5\b.*)    [NC]
RewriteCond %{QUERY_STRING}    !(desc=ph-monitor-ph-tester)     [NC]
RewriteRule ^/?index.php$       /index.php?%1&desc=ph-monitor-ph-tester      [NC,L,R=301]
0
 
LVL 1

Author Closing Comment

by:helpchrisplz
ID: 39175038
Thanks you own.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
With more and more people tethered to the internet, advertisers can reach you in new and creative ways. Push notifications on your smartphone, customized advertisements based on your previous searches, and email inboxes filled with promotional pitch…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question