Solved

htaccess 301 redirect not working

Posted on 2013-05-16
7
368 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
[X]
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
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Online promotion is consistently becoming more important for all types of businesses. From Facebook ads to search engines to YouTube videos, there are all sorts of channels that can effectively be used to promote a business or product. But how shoul…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

626 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