Solved

htaccess 301 redirect not working

Posted on 2013-05-16
7
347 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

758 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now