Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

htaccess 301 redirect not working

Posted on 2013-05-16
7
Medium Priority
?
374 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:Richard Davis
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
There is a massive demand for content on the web right now, and it doesn't look like it's going to stop any time soon. But, if you are running a business blog, it's not just enough to offer your audience lots of content. It needs to be high-quality…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

885 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