Solved

.htacess redirect not working

Posted on 2011-09-16
5
254 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
ID: 36550176
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
ID: 36550223
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
ID: 36550266
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
ID: 36550317
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
ID: 36550331
Thanks guys, worked perfectly.

:)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

808 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