Solved

.htacess redirect not working

Posted on 2011-09-16
5
251 Views
Last Modified: 2012-05-12
Hi,

I've just changed the name of one of my php pages and I'm wanting to redirect requests made to the former filename to go to the new filename.

The old page is:
news/event.php?event=

The new page is:
news/predictions.php?event=

I tried using this in .htaccess:

RewriteRule ^news/predictions.php?event=([0-9]{2}) news/predictions.php?event=$1 [r=301,nc]

I tried accessing the orginal url but it didnt redirect me to the new one. Can anyone see where i'm going wrong?

Thanks,

Paul

Am I using this wrong? I tried
0
Comment
Question by:m0tSiE
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Derokorian
Comment Utility
First you are redirecting from prediction to predictions. This is a problem. Secondly, you never close your pattern using the $ symbol. Finaly, I think you can use:

RewriteRule ^news/event.php$ news/predictions.php [QSA,R=301,NC]

HTH
0
 

Author Comment

by:m0tSiE
Comment Utility
Thanks Derokorian, I tried your code and it does redirect but it uses the full server path including public_html, etc. is there a way to stop it adding in those extra folders? or should I just change news/predictions.php to the full url?
0
 
LVL 11

Assisted Solution

by:Amar Bardoliwala
Amar Bardoliwala earned 50 total points
Comment Utility
Hello m0tSiE,

You can try any of following

1. add full url like http://yoursite.com/news/predictions.php

or

2. try /news/predictions.php

Hope this helps.

Thank You.

0
 
LVL 10

Accepted Solution

by:
Derokorian earned 450 total points
Comment Utility
Personally I use:


RewriteEngine ON
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.+) $1 [L]

#other rewriterules here such as yours:
RewriteRule ^news/event.php$ news/predictions.php [QSA,R=301,NC]

Open in new window



or you can use the leading slash as amar suggested
0
 

Author Closing Comment

by:m0tSiE
Comment Utility
Thanks guys, worked perfectly.

:)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.

763 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

12 Experts available now in Live!

Get 1:1 Help Now